# How can I find the threshold for a structure array?

2 ビュー (過去 30 日間)
Fabio Castro 2016 年 4 月 6 日
コメント済み: Fabio Castro 2016 年 4 月 8 日
Hello all,
I want to find the threshold for various trials, contained in the structure "Target_Tr.". I have previously calculated the max value (X and Y) of the baseline. I would like to have as result a structure array containing the values after the threshold. I wrote this code, but the system gives me back the error message "Undefined operator '>' for input arguments of type 'struct'. What am I doing wrong?
Thank you very much
clear a
for a = 1:length(fields_trials)
Threshold_Target_X.(['a_' int2str(a)])=find([Target_Tr.(fields_trials{a})]>Target_Max_Y);
end

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

### 採用された回答

Orion 2016 年 4 月 6 日
Hi,
I tried this code and it works :
Target_Tr.s1 = rand(10,1);
Target_Tr.s2 = rand(10,1);
fields_trials = fieldnames(Target_Tr);
Target_Max_Y = 0.6;
clear a
for a = 1:length(fields_trials)
Threshold_Target_X.(['a_' int2str(a)]) = find([Target_Tr.(fields_trials{a})]>Target_Max_Y);
end
Does your structure Target has only "direct" subfields ( Target_Tr.s1 , Target_Tr.s2,...) ?
Because if you have somethig like
Target_Tr.s3.s1 = rand(10,1); % subfield of field
then the error message makes sense.
##### 3 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
Orion 2016 年 4 月 6 日
That's really weird, because I just retried my code and it works.
If you first do a clear all, does this code work ?
Fabio Castro 2016 年 4 月 8 日
Hello.
I don't know why, but if I close and re start the matlab, then it works.
Thank you very much for the help!

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

### カテゴリ

Help Center および File ExchangeStructures についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by