Matrix dimensions must agree.
조회 수: 4 (최근 30일)
이전 댓글 표시
I am using an array value
FPR = [1.0:0.001:2.0];
n = length(FPR);
to give values into a for loop
for i = [1:1:n]
FPR(i) = (i);
in the for loop i use an if statement to interpolate an answer from a graph and it uses an array. I know that T03 and CombTD have become vectors but i dont know how to get my if statement to work for vectors and not elements. This is the code.
a = [300,400,500,600,700,800,900];
TempInlet = T03;
TempDiff = CombTD;
LSearch = find(a <= TempInlet,1,'last');
HSearch = find(a >= TempInlet,1,'first');
lower = a(LSearch);
higher = a(HSearch);
if lower>=300 && higher<=400
xlower = TempDiff/37076.92308;
yhigher = TempDiff/36230.76923;
elseif lower>=400 && higher<=500
xlower = TempDiff/36230.76923;
yhigher = TempDiff/35461.538461;
elseif lower>=500 && higher<=600
xlower = TempDiff/35461.538461;
yhigher = TempDiff/34615.384615;
elseif lower>=600 && higher<=700
xlower = TempDiff/34615.384615;
yhigher = TempDiff/33769.230769;
elseif lower>=700 && higher<=800
xlower = TempDiff/33769.230769;
yhigher = TempDiff/33230.76923;
elseif lower>=800 && higher<=900
xlower = TempDiff/33230.76923;
yhigher = TempDiff/32769.230769;
end
percentage = (TempInlet-lower)/100;
FAR = xlower+((yhigher-xlower)*percentage)
and this is the error code
Matrix dimensions must agree.
Error in Looptest (line 100)
LSearch = find(a <= TempInlet,1,'last');
댓글 수: 1
KSSV
2017년 11월 15일
Give either dimensions or values of the variables......so that we can run the code...
답변 (2개)
N.
2017년 11월 15일
The error is in these lines:
LSearch = find(a <= TempInlet,1,'last');
HSearch = find(a >= TempInlet,1,'first');
if a and TempInlet have not the same size, you cannot compare them. What do you want to do exactly ? What is "lower" and "higher" ?
댓글 수: 0
Walter Roberson
2017년 11월 15일
For vector TempInlet, you can replace
LSearch = find(a <= TempInlet,1,'last');
HSearch = find(a >= TempInlet,1,'first');
with
[~, LSearch] = histc(TempInlet, [a, inf]);
HSearch = LSearch;
mask = TempInlet ~= a(LSearch);
HSearch(mask) = HSearch(mask) + 1;
The mask will usually be true: it will only be false in the places where the temperatures are exactly on the boundary.
This is a translation of your code. However, I do not think you need HSearch or xlower or xupper and all those if statements. I think you should use just a small number of lines:
temp_divs = [37076.92308, 36230.76923, 35461.538461, 34615.384615, 33769.230769, 33230.76923, 32769.230769];
xlower = TempDiff ./ temp_divs(LSearch);
xupper = TempDiff ./ temp_divs(LSearch+1);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!