For loop, Brace indexing is not supported for variables of this type.

23 ビュー (過去 30 日間)
Alexander Guillen
Alexander Guillen 2022 年 4 月 29 日
コメント済み: Star Strider 2022 年 4 月 29 日
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));

採用された回答

Star Strider
Star Strider 2022 年 4 月 29 日
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
a = 8×1
0 0 0 0 0 0 0 0
With that change, it works.
.
  4 件のコメント
Image Analyst
Image Analyst 2022 年 4 月 29 日
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
Star Strider 2022 年 4 月 29 日
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
All_Values = 8×1 cell array
{10×8 cell} {10×8 cell} {10×8 cell} {10×8 cell} {10×8 cell} {10×8 cell} {10×8 cell} {10×8 cell}
[rows,cols] = cellfun(@size, All_Values)
rows = 8×1
10 10 10 10 10 10 10 10
cols = 8×1
8 8 8 8 8 8 8 8
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
La = 10×1 cell array
{[0 0 0 0]} {[0 0 1 0]} {[0 0 0 0]} {[1 0 0 0]} {[1 0 0 0]} {[0 0 0 0]} {[0 0 1 1]} {[0 1 0 0]} {[0 1 1 1]} {[0 1 1 0]}
Operator '>' is not supported for operands of type 'cell'.
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.
.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 4 月 29 日
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:

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by