Error using length, Too many input arguments.
1 回表示 (過去 30 日間)
古いコメントを表示
I have a bunch of data from animal cells at different times. j represents the time frame. I want to extract a field from my object and that field can either have one or two values. If I have one value, I want to extract the value as it is and if I have two values, I want to average them out. This is a snippet of my code.
if length(Obj.MatFile{cellnumber}{j},ExtractField)==2
Answer(icellnumber,i)=mean(Obj.MatFile{cellnumber}{j}.(ExtractField));
else
Answer(icellnumber,i)=Obj.MatFile{cellnumber}{j}.(ExtractField);
end
I keep getting the above error. Any help would be greatly appreciated. Thanks in advance.
0 件のコメント
採用された回答
その他の回答 (1 件)
Stephen23
2021 年 8 月 31 日
編集済み: Stephen23
2021 年 8 月 31 日
if length(Obj.MatFile{cellnumber}{j}.(ExtractField))==2
But note that you do not need to check the length: taking the mean of one value simply returns that value, so in both cases you can simply do this (and not worry about how many values there are):
Answer(icellnumber,i) = mean(Obj.MatFile{cellnumber}{j}.(ExtractField));
and then get rid of the IF entirely.
2 件のコメント
Walter Roberson
2021 年 9 月 1 日
"if there are more than two" -- use numel() instead of length() if you want to know how many values there are. length() has a slightly different meaning.
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!