MATLAB Answers

Assignment between unlike types is not allowed for two function in a loop

조회 수: 3(최근 30일)
DulceEien
DulceEien 2021년 7월 28일
댓글: DulceEien 2021년 7월 28일
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

채택된 답변

Walter Roberson
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by