plot many columns to different figure

9 visualizaciones (últimos 30 días)
Fani
Fani el 6 de Sept. de 2014
Comentada: Star Strider el 9 de Sept. de 2014
Hello! I have 2004 columns of data. I want to plot the first column (X) with all others (Y). i.e.: plot(X,Y1) plot(X,Y2) . . . plot(X,Y2004)
If I do this and run the program, I take one figure only with the first plot. If I write plot(X, Y(:,1:2004)), I take one figure with 2003 lines. I don't want this. I want to take 2003 figures which are X,Y1, the other figure will be X,Y2 and so on. Also, I would like to do this in one step.
Is there an idea?
Thank you for your help.

Respuesta aceptada

Star Strider
Star Strider el 6 de Sept. de 2014
You could create a for loop to generate 2004 different plots if you want to:
for k = 1:2004
figure(k)
plot(X, Y(:,k))
end
I would not.
I would use a ribbon plot for what you want to do. There is no way 2004 different plots are going to be meaningful otherwise.
  2 comentarios
Star Strider
Star Strider el 8 de Sept. de 2014
II am not certain I understand: ‘I want to do linear fitting and save all these as bmp images. I did linear fitting in each figure separately, but I'd like to do this into the loop!’
You can use polyfit to do the fitting, and then polyval if you want to plot the regression as well:
X = sort(rand(10),2);
Y = sort(rand(10),2);
for k1 = 1:size(X,1)
cfs(k1,:) = polyfit(X(k1,:), Y(k1,:), 1);
yf = polyval(cfs(k1,:), X(k1,:));
figure(k1)
plot(X, Y(:,k1),'+b', X(k1,:),yf,'-r')
print(sprintf('Figure(%d).bmp',k1), '-dbmp')
end
I tested everything but the print call in that loop (since I didn’t want to have to go deleting those files), so you may have to experiment with that line in your application. The first column of ‘cfs’ has the slopes and the second column the intercepts for each regression. I do not have your data so I cannot use it to design my code, but I would do something like what I outlined here if I were to do what I believe you want to do.
Star Strider
Star Strider el 9 de Sept. de 2014
‘I added the function p=polyfit(X,Z(:,k)) or the function linearFit(X,Z(k)) and did not work.’
You have to tell polyfit the order of the polynomial you want to fit. For a linear fit, the order is 1.
Use this:
p=polyfit(X, Z(:,k), 1);

Iniciar sesión para comentar.

Más respuestas (4)

Image Analyst
Image Analyst el 6 de Sept. de 2014
There is no way you're going to see 2002 plots of data unless you have a very large monitor. I would not use bar charts, line/curves, ribbon plots or anything like that. I'd display it as an image. Even then, unless you have more than 2003 pixels across, you're not going to see all the columns. I'm not sure what your x is but assuming that the x's are linearly spaced and increasing, I'd just display the y as an image:
image(Y(:,2:end));
Apply a colormap if you want
colormap(jet(256)); % Or gray(256)
colorbar;
If your monitor is not 2003 columns across, MATLAB will shrink the image down so that it fits on the screen, though you can zoom it up to the original size if you want. So each column is a line of pixels on your monitor. No other type of display (ribbons, or other 3D-like graphics) will fit - you won't see them unless you are zoomed in so much that you then won't see the entire data set at the same time.
The other option is to use plot() with a different color for each column and plot everything on one axes. Of course they'll all pile on top of each other but it will let you see the average (i.e., the band of curves where the bulk of the curves lie) and outlier curves. In fact you might plot the average over the mess of lines in a thicker line in a color like red so you can see it. But I think an image is better, particularly if there is some relationship/correlation between nearby columns.

Fani
Fani el 8 de Sept. de 2014
Editada: Fani el 8 de Sept. de 2014
Thank you for your help!! Ι used the first answer. Νevertheless, 2000 columns are too much for the programm to my computer. So, i do this in steps of 500 columns!!
I would also like to ask something!! Ιn these figures, I want to do linear fitting and save all these as bmp images. I did linear fitting in each figure separately, but i'd like to do this into the loop!
Thank you again for your help!
  1 comentario
Image Analyst
Image Analyst el 8 de Sept. de 2014
I'm not sure what you did. Did you use plot() or ribbon() as Star suggested, or an image like I suggested? Who are you replying to? I'm not sure what kind of BMP image you want. Can you show us a screenshot of what you're starting with? With my suggestion you'd already have an image, but I don't know what you mean by doing a "linear fitting". Fitting of what to a line?

Iniciar sesión para comentar.


Fani
Fani el 9 de Sept. de 2014
Editada: Fani el 9 de Sept. de 2014
I have the loop:
X=data(:,1); % air mass
Y=data(:,5:2008); %irradiance 2004 column
Z=log(Y); % log irradiance all column
for k=1:500
figure(k)
plot(X,Z(:,k))
xlabel('airmass')
ylabel('logirradiance(W/m^2)')
end
This loop make me 500 figures. In these figures I want to do linear fitting and then I save to my computer as bmp or jpg images.
  2 comentarios
Star Strider
Star Strider el 9 de Sept. de 2014
@Fani — I outlined a way to do what you want in my comment to my Answer yesterday. What about that did not work?

Iniciar sesión para comentar.


Fani
Fani el 9 de Sept. de 2014
my data make the blue curve. I want to do the linear fitting (red line). I did this from tools-basic fitting-linear.
nevertheless, i have 2000 figure in which i must do it. this is very time consuming, if I do by hand. So, i want to insert a function to my loop, which will do this in all figure.
my loop is:
X=data(:,1);
Y=data(:,5:2008);
Z=log(Y);
for k=1:500
figure(k)
plot(X,Z(:,k))
xlabel('airmass')
ylabel('logirradiance(W/m^2)')
end
I added the function p=polyfit(X,Z(:,k)) or the function linearFit(X,Z(k)) and did not work.

Categorías

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