This is my code for plotting... However when I plot my spectrum data using this code, it is showing only 1 row. How can I plot all 150 rows? Can anyone help me to solve this?

 for i=1:length(dataheader.nrgb)

closed as off-topic by MBaz, lennon310, jojek Mar 11 at 14:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "General programming questions are off-topic here, but can be asked on Stack Overflow." – MBaz, lennon310, jojek
If this question can be reworded to fit the rules in the help center, please edit the question.


By default, matlab's plot command clears the plot area before drawing the new curve.

To prevent this, and allow multiple curves to appear on the same figure, you can activate the hold mode:

hold off; % 1st plot will clear figure
for i = 1:length(data header.nrgb)
   hold on; % set hold mode for subsequent figures

Alternatively you can stack multiple copies of freq and the plot command will draw one curve per column. Since your data is organized by rows, you'll need to transpose your data matrix:

% just make sure freq & height are column vectors. This may not be necessary if they already are.
if size(freq,1) < size(freq,2)
   freq = transpose(freq);
if size(height,1) < size(height,2)
   height = transpose (height);

% plot one curve per column on same figure
N = length(data header.nrgb);
plot(repmat(freq,1,N), transpose (arraydata)+repmat(height,1,N))

Not the answer you're looking for? Browse other questions tagged or ask your own question.