Difficulties in axes scaling on matrices: 500 values should be 200 Hz - how to handle?

Hello community,
As described I have difficulties in scaling axes on 3d (or 2d) plots.
For example I have a 100x500 matrix = A
Due to the resolution in data aquisition I have 100 Values on the time axe y and 500 values on the frequency axe x.
I want an easy way in coding that those 500 values describing 200 Hz, and that those 100 Values describing 6 hours.
Until now I always changed the width of the matrix with a factor, so that I only have 200 values.
if true
% maxfr1=zeros(109,1);
maxfr2=zeros(109,1);
maxfr3=zeros(109,1);
maxfr4=zeros(109,1);
for i1= 1:109
maxfr1(i1,1)=maxidx_smooth1(i1,1)*0.39;
maxfr2(i1,1)=maxidx_smooth2(i1,1)*0.39;
maxfr3(i1,1)=maxidx_smooth3(i1,1)*0.39;
maxfr4(i1,1)=maxidx_smooth4(i1,1)*0.39;
end
end
When I plot a 2d or a 3d graph its shown correctly then. But this is very uncomfortable and erases my higher resolution in data aquisition. Until now I have not found a way to do it easily interactive (change ticks only adds or deletes values but is not changing the whole scale)...
I certainly need help :)
Thank you

 Accepted Answer

At first you could cleanup the posted code - you do not nee a loop:
maxfr1 = maxidx_smooth1 * 0.39;
maxfr2 = maxidx_smooth2 * 0.39;
maxfr3 = maxidx_smooth3 * 0.39;
maxfr4 = maxidx_smooth4 * 0.39;
It would be even easier, if you store the vectors in one matrix.
But I assume, I do not understand the actual problem.
[EDITED]
It would be clearer, if you post Matlab code, which reproduces your problem. I assume you need to specify the values of the X-direction:
y = rand(50, 10); % Smaller for simplicity
figure
plot(y); % Your problem, x-values are the indices
figure
x = linspace(0, 200, 50);
plot(x, y); % Scaled x-values

More Answers (2)

OK. I try to describe it easier.
I need a 2d plot of a matrix. The matrix has the dimensions 100x500.
I recorded the data in the matrix with 3 values per second for a higher resolution.
If I want to plot the matrix now - the x-axis goes from 0 to 500. Those 500 values representate lets say 200 Hz. So in the plot there shouldn´t be shown the number of values i have - "500" BUT INSTEAD the 200 Hz but on the same location where now "500" is...
If I do change "X-Limits" which is now from 0 to 500 into 0 to 200 it simply just cuts off the rest of the graph. But I want the whole graph displayed just with the x-axis scale 0 to 200.
I hope this was understandable - picture didn´t work.
Thanks

6 Comments

What does "picture didn't work" mean?
Instead of "if I want to plot..." post the corresponding code, because the actual problem is hidden in it.
Hello again,
sorry for confusion - in my head the problem description sounds logical ;)...
if true
% scale problems with plot
% %%create matrix
A = rand(109,512);
for i= 1:10
A(:,40+i)=30;
end
% %%create plot
figure1 = figure(1);
plot1 = surf(A);
%plot1 shows now a 3d plot with 512 values in x-direction, 109 in
%y-direction and 30 values in z-direction. the values of the x-direction
%are showing a frequency range from 20 to 200 Hz. This means i have to
%"rename" the x-axis scales that it is shown correctly in the figure.
%Otherwise someone who dont knows what i have done, thinks we have a
%frequency range from 0 to 500 Hz. end
There is no reason for apologies, because you are the only one who suffers from missing answers.
Have you seen my new suggestion after the [EDITED] tag?
I have tried the linspace function and its pretty good. Sounds like that what I needed. Are there any ways to do this interactive - when the plot is already created?
Thanks
Yes.
Set(AxesHandle, 'XData', linspace(0, 200, 50))
The AxesHandle can ge found e.g. by clicking on the axes and using gca afterwards.
Ok works great now but just for 2d graphs....!!! Thank you very much for your effort !!!

Sign in to comment.

ok as i told you the linspace function works with 2d plots.
but i have another problem with a 3d plot: Please try this
GG2 =rand(109,512);
figure43 = figure(43);
surf(GG2)
figure44 = figure(44);
x = linspace (20,200,2);
surf(x,GG2(:,1),GG2);
I do want the same graph than in figure43 but the x-axis range should go from 20 to 200 and not from 0 to 600.
The figure44 shows nothing...
Is this possible somehow?
Regards,

Asked:

on 10 Sep 2012

Community Treasure Hunt

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

Start Hunting!