Code works in Command Window but not in a script... Find Function
12 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Kelly Kearney
2015-12-16
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!