How to save a data when something happens

1 visualización (últimos 30 días)
mahdi safarzadeh
mahdi safarzadeh el 17 de Nov. de 2013
Comentada: Image Analyst el 18 de Nov. de 2013
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.

Respuestas (3)

Image Analyst
Image Analyst el 17 de Nov. de 2013
Editada: Image Analyst el 17 de Nov. de 2013
if symbolValue > 0.51
savedSymbolValue = symbolValue;
% Optionally save to a mat file
save(yourMatFileName, 'savedSymbolValue');
end
  5 comentarios
mahdi safarzadeh
mahdi safarzadeh el 18 de Nov. de 2013
Thanks a lot for your answer. the find() function solution is way simpler and i am gonna try to use it in my codes. Thanks a agin.
Image Analyst
Image Analyst el 18 de Nov. de 2013
Please mark the best answer as "Accepted" if you're done with this topic. Thanks.

Iniciar sesión para comentar.


Umair Nadeem
Umair Nadeem el 17 de Nov. de 2013
Editada: Umair Nadeem el 17 de Nov. de 2013
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 comentarios
Image Analyst
Image Analyst el 17 de Nov. de 2013
Editada: Image Analyst el 17 de Nov. de 2013
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)
mahdi safarzadeh
mahdi safarzadeh el 18 de Nov. de 2013
of course I changed the C to Matlab code. the "find()" function solution is way simpler, I am gonna try to use it in my codes. But Umair's solution worked for may case. Thanks anyway.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 17 de Nov. de 2013
find(Symbolvalue >= 0.5, 1, 'first')
  2 comentarios
mahdi safarzadeh
mahdi safarzadeh el 17 de Nov. de 2013
Thanks a lot Walter, your solution looks really tempting but I dont know why it didnt work for my case! anyway, thanks a lot.
Image Analyst
Image Analyst el 17 de Nov. de 2013
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by