Enter values into x array and y array
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I have sorted the data out of the txt file. I wonder how could I enter the year and dat into an x and y array respectively so that I can plot (x,y). Thank you.
filename = input('Please enter the file name: ');
fid01 = fopen(filename,'r');
for i= 1:15
line = fgets(fid01);
end
for i = 16:66
line = fgets(fid01);
z = strread(line,'%s');
year = str2num(z{1});
for j = 2:13
dat = str2num(z{j});
if ( dat== -99.9900)
dat = NaN;
end
year = year + (j-1)/12 ;
x = year;
y = dat;
fprintf('%f %f\n',x,y);
end
end
0 Kommentare
Antworten (1)
Walter Roberson
am 20 Feb. 2016
fmt = repmat('%f',1,14);
fid = fopen('CO2.txt','rt');
data = textscan(fid, fmt, 'HeaderLines', 15, 'CollectOutput', 1);
fclose(fid);
x = bsxfun(@plus, data{1}(:,1), (0:11)/12);
y = data{1}(:,2:13);
y(y<0) = nan;
plot(x, y);
legend({'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'});
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!