For loup not working

102 vues (au cours des 30 derniers jours)
Simon
Simon le 29 Jan 2026 à 13:44
Commenté : Simon le 3 Fév 2026 à 6:02
Hey everyone!
I am using this code with a for loop to set paramaters of a FMU.
It worked fine until I added a new parameter into VSDConfig.xlsx table.
The function still works for most parameters. However, the new parameter is set to 0 instead of the actual value.
Also, this only happens when the for loop is used. When I tried to set the new paramater by indexing its number, it worked fine. see below:
SetFmuParam(fmuImportName,string(VarNames(19)),cell2mat(Vars(19))); (worked)
I have run a loop to check if the indexing is right and it was:
for i=1:length(VarNames)
string(VarNames(i))
cell2mat(Vars(i))
end
result for i=19:
...
ans =
"Industry.M5_Application.M5_3_Load.M5_3_2_Inertia.P5_3_2_3_System_Inertia"
ans =
0.0104
...
Everything seems to work fine part by part, until I put it together using the for loop.
Please help.
Original code:
function FMUConfig(PumpDisp)
fmuImportName = 'iC7_IndustryDriveTrain_Uut/FMU';
fmuName = get_param(fmuImportName,'FMUName'); % Finds FMU name
filename = "VSDConfig.xlsx";
VSDConfig = readcell(filename);
missing = cellfun(@anymissing, VSDConfig);
VSDConfig(missing) = {0};
data = VSDConfig(2:end,2:end);
RowNames = VSDConfig(2:end,1);
VarNames = VSDConfig(1,2:end);
idx = [RowNames{:}] == PumpDisp;
Vars = data(idx,:);
for i = 1 : length(VarNames)
SetFmuParam(fmuImportName,string(VarNames(i)),cell2mat(Vars(i)));
end
end
  10 commentaires
dpb
dpb le 2 Fév 2026 à 14:05
Thanks for letting know that the issue was uncovered.
Just for the future, note that the problem could have been found much sooner if had attached the input file with the initial question or at least as follow-up when requested. It oftentimes as here is simply not possible to diagnose a problem without having the necessary input to be able to reproduce the issue. So, when it's time to ask again, "help us help you!" by making it possible to reproduce the problem easily.
Simon
Simon le 3 Fév 2026 à 6:02
Sure, sorry, I will remember that. Thanks again.

Connectez-vous pour commenter.

Réponses (1)

dpb
dpb le 30 Jan 2026 à 18:43
"...However, the new parameter is set to 0 instead of the actual value."
function FMUConfig(PumpDisp)
fmuImportName = 'iC7_IndustryDriveTrain_Uut/FMU';
fmuName = get_param(fmuImportName,'FMUName'); % Finds FMU name
filename = "VSDConfig.xlsx";
VSDConfig = readcell(filename);
missing = cellfun(@anymissing, VSDConfig);
VSDConfig(missing) = {0};
...
The symptoms are entirely consistent with the above having set that column of data to zero...your test loop doesn't test the values you actually passed, only something read. But, we can't debug without the data to be able to reproduce what may have caused/is causing the problem.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by