# how can I plot a power spectrum for 150 range bins with 512 fft points [closed]

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)
plot(freq,arraydata(i,:)+height(i))
end


## 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
plot(freq,arraydata(i,:)+height(I));
hold on; % set hold mode for subsequent figures
end


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);
end
if size(height,1) < size(height,2)
height = transpose (height);
end

% plot one curve per column on same figure