Assignment between unlike types is not allowed for two function in a loop
4 次查看(过去 30 天)
显示 更早的评论
hi, I converted the variables, S, V and D into struct, because I am using two criteria to evaluate, in the end the variable name is the same and I have to do a sum of those values, what should change (in Matlab I have the following error: Assignment between unlike types is not allowed) Is it possible to save them like this? or better I change the name of the variable as S1, S2 etc and at the end in my equation I add one by one.
For the first loop is working but after it finishes
%% Cracks
for i = 1:5
load([DataFolder '\' sprintf('beam_crack_%d.mat',i)]);
[S(i,:),V(i,:),D(i,:), n(i,:), Zi(i,:)] = bc_DE(beam_crack);
end
%% Spalling
for i = 1:5
load([DataFolder '\' sprintf('beam_spalling_%d.mat',i)]);
[S(i,:), V(i,:), D(i,:), n(i,:)] = bs_DE(beam_spalling);
end
In the function, one variable look like this
S.S1 = input('Input damage structural stability rate (S) (0-4) :');
while S.S1 <0 || S.S1 > 4
disp('Not a valid number please try again')
S.S1 = input('Enter a whole number between 0 and 4:');
end
0 个评论
采纳的回答
Walter Roberson
2021-7-28
It looks like your function is returning struct variables.
When you have code of the form
struct1(index) = struct2
where struct1 is a structure, then that will fail if struct2 is []. It will also fail if struct2 has a different set of fields than struct1 has. Furthermore it will fail if all of the fields are the same but the fields are in a different order.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!