Borrar filtros
Borrar filtros

Code works in Command Window but not in a script... Find Function

10 visualizaciones (últimos 30 días)
Code running on Matlab 2013a, Mac OSX 10.9.5
indices_TempMin = find(nbar(:,8) == Cyl_1(1,5));
When using the above syntax in my code, the code returns an empty matrix, but copying the code to the command window gives the answer I'm looking for;
>> indices_TempMin = find(nbar(:,8) == Cyl_1(1,5))
indices_TempMin =
9
25
41
57
73
89
105
121
137
153
Both nbar(:,8) and Cyl_1(:,5) are vectors containing temperature values which are known as they were specified by me earlier in my code. They are not results of calculations leading to unknown precision (I don't think), they are specified selected and arranged by my code.
Another example,
I know that,
>> Cyl_1(1,5)
ans =
2300
My vector of nbar(:,8) is as shown below and merely repeats itself 10 or so times >>
nbar(:,8)
ans =
1500
1600
1700
1800
1900
2000
2100
2200
2300
2400
2500
2600
2700
2800
2900
3000
If I enter indices_TempMin = find(nbar(:,8) == 2300) in the script the answer is what I expect but it just doesn't work when i use indices_TempMin = find(nbar(:,8) == Cyl_1(1,5));
I have tried specifying a range around the value of Cyl_1(1,5) but still this doesn't work. Also, if I were to enter:
Cyl_1(1,5) which is known to be 2300 - some location inside nbar(:,8) known to be 2300 I will get 0 as expected.
I don't feel as though it's a precision error as the values of temperature are specified and not calculated as such. The source of the temperature variables is a linspace function. This function is used once at the beginning of the code and then any further uses of temperature are pulled from this variable into my other variables... I realise this is probably not the most efficient technique from a programming perspective, but I'm not a programmer, I'm an engineer and this approach allows me to visualise and work with my data easier.
My linspace of temperature is executed as follows:
LowTempLim = 1500;
StepSize = 100;
Temperature = linspace(LowTempLim,3000,((3000-LowTempLim)/StepSize) + 1)';
Any help or suggestions on getting my code to work would be greatly appreciated
Cheers

Respuesta aceptada

Kelly Kearney
Kelly Kearney el 16 de Dic. de 2015
I suggest putting a breakpoint in your code at the line
indices_TempMin = find(nbar(:,8) == Cyl_1(1,5));
and run it again. When it pauses, check to make sure nbar and Cyl_1 really contain the values you think they should.
  1 comentario
Angry Sloth
Angry Sloth el 16 de Dic. de 2015
I feel like a fool but I can't thank you enough... Entirely my mistake (I'm certainly not a programmer).
Basically, I had another piece of code running after
indices_TempMin = find(nbar(:,8) == Cyl_1(1,5));
which continued sorting and deleting values which led me to why the syntax was working in the command window... Moving this piece of code to it's proper place meant the values at the breakpoint where as expected and now my code works.
Thank you very much for your time Kelly. Much appreciated especially considering how trivial my mistake was.
Thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by