Why don't my variables index properly?
1 回表示 (過去 30 日間)
古いコメントを表示
MATRIX DIMENSIONS 119 X 9
for J = 260:262
%******************************** WORKS FINE ******************************
start_string = num2str(J);
index =
strmatch(start_string,tline(headerlines+1:length(tline)))+headerlines;
if J == 260
a = min(index)-1; % a = 2 -- this is correct
n = max(index); % n = 23 -- this is correct
for i = a:n
s = s + Ra(i);
t = t + Rs(i);
u = u + RH(i);
v = v + Rn(i);
w = w + G(i);
x = x + Ta(i);
y = y + Ts(i);
z = z + U2(i);
end
%******************************* PROBLEM AREA *****************************
elseif J > 260 & J <= 261
% a = index;
a = min(index); % a = 24 -- this is correct
n = max(index); % n = 72 -- this is correct
for i = a:n
% s = s + Ra(i); %INDEX EXCEEDS MATRIX DIMENSIONS
% t = t + Rs(i);
% u = u + RH(i);
% v = v + Rn(i);
% w = w + G(i);
% x = x + Ta(i);
% y = y + Ts(i);
% z = z + U2(i);
else J > 261
a = min(index); % a = 73 -- this is correct
n = max(index); % n = 119 -- this is correct
end
end
0 件のコメント
回答 (2 件)
Image Analyst
2017 年 5 月 25 日
Use &&:
elseif J > 260 && J <= 261
4 件のコメント
Image Analyst
2017 年 5 月 26 日
You forgot to attach the second csv file opened by the m-file: 'BiometDataSetTestData_2.csv'
Star Strider
2017 年 5 月 25 日
This is a complete guess since I don’t know your data.
See if:
for i = 1:(n-a+1)
works. If you extracted your vectors from your original data, they would lose their original indices, so the indices would start with 1.
I’ll delete my Answer if I guessed wrong.
2 件のコメント
Star Strider
2017 年 5 月 25 日
It might be best to go back and see if the code you used to extract your data is doing it correctly.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!