How to save a data when something happens
1 回表示 (過去 30 日間)
古いコメントを表示
Hello everybody, I am receiving 100 symbols, with values starting from 0 and go to 1. The scenario is like this.
for i=1:100
if Symbolvalue >= 0.5
Nuberofsymbolvalue=i;
end;
end;
I need to save the the first i in which I go above 0.5
Thanks in advance.
0 件のコメント
回答 (3 件)
Image Analyst
2013 年 11 月 17 日
編集済み: Image Analyst
2013 年 11 月 17 日
if symbolValue > 0.51
savedSymbolValue = symbolValue;
% Optionally save to a mat file
save(yourMatFileName, 'savedSymbolValue');
end
5 件のコメント
Image Analyst
2013 年 11 月 18 日
Please mark the best answer as "Accepted" if you're done with this topic. Thanks.
Umair Nadeem
2013 年 11 月 17 日
編集済み: Umair Nadeem
2013 年 11 月 17 日
you can use this
index = 1;
for i = 1:100
if SymbolValue >= 0.5
NumberofSymbolValue[index] = i;
index += 1;
end
end
Valueoffirst_i = NumberofSymbolValue[1];
The first value in array NumberofSymbolValue will show the first i
Hope it helps
4 件のコメント
Image Analyst
2013 年 11 月 17 日
編集済み: Image Analyst
2013 年 11 月 17 日
How did it work? Are you programming in C? MATLAB doesn't use [] around array indexes and doesn't have the += operator. Plus, his solution could be done with a non-looping simple call to find like Walter and my solution.
allHighSymbolIndexes = find(Symbolvalue >= 0.5)
Walter Roberson
2013 年 11 月 17 日
find(Symbolvalue >= 0.5, 1, 'first')
2 件のコメント
Image Analyst
2013 年 11 月 17 日
Just assign the output to something:
firstHighSymbolIndex = find(Symbolvalue >= 0.5, 1, 'first')
theFirstHighSymbol = Symbolvalue(firstHighSymbolIndex);
We don't know why it didn't work because you didn't show your code. The code you used (a for loop) is not vectorized and not as MATLAB-ish but is probably still fast enough.
参考
カテゴリ
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!