For loop, Brace indexing is not supported for variables of this type.
23 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexander Guillen
am 29 Apr. 2022
Kommentiert: Star Strider
am 29 Apr. 2022
This is my for loop, I wasnt too sure how set up the for loop
All_Values = [ ElecsB; ElecsU; EarsB; EarsU; FaceB; FaceU; NeckB; NeckU];
for i = 1: length(All_Values)
a(i,:) = length(find(All_Values{i}(:,4)>25))/length(All_Values{i}(:,4));
end
I am getting this error message. Can you please point me how to fix this error?
Brace indexing is not supported for variables of this type.
Error in Allmodels (line 18)
a(i,:) = length(find(All_Values{i}(:,4)>25))/length(All_Values{i}(:,4));
0 Kommentare
Akzeptierte Antwort
Star Strider
am 29 Apr. 2022
The ‘All_Values’ matrix is not a cell array, so you cannot use cell array indexing for it. (I am not exactly certain what it contains.)
If it is defined as:
[ ElecsB, ElecsU, EarsB, EarsU, FaceB, FaceU, NeckB, NeckU] = deal(rand(1,10)*35); % Create Unsupplied Variables
All_Values = { ElecsB; ElecsU; EarsB; EarsU; FaceB; FaceU; NeckB; NeckU }; % Define As Cell Array
for i = 1: length(All_Values)
a(i,:) = length(find(All_Values{i}(:,4)>25))/length(All_Values{i}(:,4));
end
With that change, it works.
.
4 Kommentare
Image Analyst
am 29 Apr. 2022
OK, great, but you still might want to review the link I gave below. There is lots of other good stuff in the FAQ too besides that.
Star Strider
am 29 Apr. 2022
Note that length is a bit ambiguous with respect to cell arrays.
[ ElecsB, ElecsU, EarsB, EarsU, FaceB, FaceU, NeckB, NeckU] = deal(mat2cell(rand(10,32)*35, ones(1,10), 4*ones(1,8))); % Create Unsupplied Variables
All_Values = { ElecsB; ElecsU; EarsB; EarsU; FaceB; FaceU; NeckB; NeckU } % Define As Cell Array
[rows,cols] = cellfun(@size, All_Values)
for i = 1: length(All_Values)
La = cellfun(@gt,All_Values{i}(:,4), repelem({25},rows(1),1), 'Unif',0) % Logical Array
a(i,:) = length(find(All_Values{i}(:,4)>25))/length(All_Values{i}(:,4));
end
I managed to get the comparison working and producing the ‘La’ logical array. I leave the rest to you, since I’m not certain what you want to do.
The error refers to the ‘a(:,i)’ assignment. That is solved in ‘La’ and since I do not understand what the ‘a(i,:)’ assignment does so I defer to you to implement it.
.
Weitere Antworten (1)
Image Analyst
am 29 Apr. 2022
All_Values is not a cell array. It is a normal double array (probably) so you should use parentheses.
See the FAQ for a description of cell arrays and when to use braces, parentheses, and brackets:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!