Why don't my variables index properly?

1 visualización (últimos 30 días)
Martin Matisoff
Martin Matisoff el 25 de Mayo de 2017
Comentada: Image Analyst el 26 de Mayo de 2017
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

Respuestas (2)

Image Analyst
Image Analyst el 25 de Mayo de 2017
Use &&:
elseif J > 260 && J <= 261
  4 comentarios
Martin Matisoff
Martin Matisoff el 26 de Mayo de 2017
Here you go. Any help would be much appreciated.
Image Analyst
Image Analyst el 26 de Mayo de 2017
You forgot to attach the second csv file opened by the m-file: 'BiometDataSetTestData_2.csv'

Iniciar sesión para comentar.


Star Strider
Star Strider el 25 de Mayo de 2017
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 comentarios
Martin Matisoff
Martin Matisoff el 25 de Mayo de 2017
Thank you for your patience.
I hope I'm not muddying the water.
You are correct, I am extracting the vectors from the original data, there are 119 records divided into three groups of data (day of year 260 through 262).
The first iteration works perfectly. For x = 260 (day of year), I extract the min value (a = 2) and the max value for (n = 23). Everything increments properly.
It when I advance to the second and third iterations that everything goes haywire. I checked, the min value for new "a" is 24, and the max value for new "n" is 71. When I enter the values for i = a:n only the first record values show 48 times.
This is driving me nuts.
Star Strider
Star Strider el 25 de Mayo de 2017
It might be best to go back and see if the code you used to extract your data is doing it correctly.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB 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