Hello guys, the for loop only gives me the last value of the .csv file. Some people have the same issue as mine seam. Most posts recommend adding a zero vector. I added the zero vector, but the problem is still remaining.
Data_table = readtable('20170401damlbmp_zone.csv')
Data_20170401 = readmatrix('20170401damlbmp_zone.csv')
% take the N.Y.K and North inromation from the loaded files
North_20170401 = zeros(360,6);
N_Y_K_20170401 = zeros(360,6);
for i = 10 :15 : 360
%for j = 1:1:24
disp( Data_20170401(i,3))
N_Y_K_20170401(i,1)= Data_20170401(i,3);
x= i+1;
North_20170401(i,1) = Data_20170401(x,3);
% end
end

1 commentaire

Can you upload the data, using the paperclip icon in the INSERT section of the toolbar?

Connectez-vous pour commenter.

 Réponse acceptée

There are likely a lot of zeros in the vectors because of the way ‘i’ is defined.
The loop is likely not necessary anyway.
Try something like this —
i = 10 : 15 : 360;
N_Y_K_20170401 = Data_20170401(i,3);
North_20170401 = Data_20170401(i+1,3);
.

7 commentaires

thank you, I tried it and it dive one value instead of a vector
Something is plainly wrong with the variables read from the files, then. I suspect that there are actually very few of them, possibly less than 25.
Reiterating my comment above, if you post the actual data it will be easier to diagnose the problem.
@the cyclist I attached the .CSV file
The ‘Time Stamp’ variable is a bit ambiguous and needs clarification, however my code works with this file, producing 2 (24x1) vectors (with a slight change in the subscripting, using curly braces {} instead of parentheses () to return a double array instead of a table) —
Data_20170401 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/867505/20170401damlbmp_zone.csv', 'VariableNamingRule','preserve')
Warning: The DATETIME data was created using format 'MM/dd/uuuu HH:mm' but also matched 'dd/MM/uuuu HH:mm'.
To avoid ambiguity, supply a datetime format using SETVAROPTS, e.g.
opts = setvaropts(opts,varname,'InputFormat','MM/dd/uuuu HH:mm');
Data_20170401 = 360×6 table
Time Stamp Name PTID LBMP ($/MWHr) Marginal Cost Losses ($/MWHr) Marginal Cost Congestion ($/MWHr) ________________ __________ _____ _____________ _____________________________ _________________________________ 04/01/2017 00:00 {'CAPITL'} 61757 42.86 0.49 -31.81 04/01/2017 00:00 {'CENTRL'} 61754 12.27 0.14 -1.56 04/01/2017 00:00 {'DUNWOD'} 61760 34.44 0.98 -22.9 04/01/2017 00:00 {'GENESE'} 61753 11.68 -0.08 -1.19 04/01/2017 00:00 {'H Q' } 61844 10.26 -0.31 0 04/01/2017 00:00 {'HUD VL'} 61758 33.04 0.88 -21.6 04/01/2017 00:00 {'LONGIL'} 61762 34.9 1.44 -22.9 04/01/2017 00:00 {'MHK VL'} 61756 13.07 0.15 -2.36 04/01/2017 00:00 {'MILLWD'} 61759 34.57 0.97 -23.03 04/01/2017 00:00 {'N.Y.C.'} 61761 34.48 1.09 -22.83 04/01/2017 00:00 {'NORTH' } 61755 10.15 -0.41 0 04/01/2017 00:00 {'NPX' } 61845 38.27 0.75 -26.95 04/01/2017 00:00 {'O H' } 61846 12.04 -0.1 -1.57 04/01/2017 00:00 {'PJM' } 61847 21.21 0.37 -10.28 04/01/2017 00:00 {'WEST' } 61752 12.24 0.15 -1.53 04/01/2017 01:00 {'CAPITL'} 61757 39.35 0.5 -28.28
i = 10 : 15 : 360;
N_Y_K_20170401 = Data_20170401{i,3}
N_Y_K_20170401 = 24×1
61761 61761 61761 61761 61761 61761 61761 61761 61761 61761
North_20170401 = Data_20170401{i+1,3}
North_20170401 = 24×1
61755 61755 61755 61755 61755 61755 61755 61755 61755 61755
PTIDu = unique(Data_20170401{:,3}); % Information: Inique Values
idx61755 = find(Data_20170401{:,3} == 61755) % Information: Find Indices
idx61755 = 24×1
11 26 41 56 71 86 101 116 131 146
D61755 = diff(idx61755) % Information: Find Intervals
D61755 = 23×1
15 15 15 15 15 15 15 15 15 15
idx61761 = find(Data_20170401{:,3} == 61761) % Information: Find Indices
idx61761 = 24×1
10 25 40 55 70 85 100 115 130 145
D61761 = diff(idx61761) % Information: Find Intervals
D61761 = 23×1
15 15 15 15 15 15 15 15 15 15
Further investigation reveals that the ‘PTID’ values repeat periodically (every 15 indices) so the same number always presents in the vectors.
So the loop is not necesary.
Has the problem been solved?
.
Thank you a lot
As always, my pleasure!
.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by