Filter löschen
Filter löschen

How to specify equal distance interval in matlab plots

5 Ansichten (letzte 30 Tage)
Raj Arora
Raj Arora am 29 Mär. 2023
Kommentiert: Raj Arora am 29 Mär. 2023
I have a set of data. I want to plot this data at equal intervals but this data is clustered at some location (top and bottom axis). I am using this command (1:3:length(vel)) but this is reading every 3rd data, but at a specific location I want more data and on the other side I want less data. How can I do this?
I have attached a code below mentioning the data and the figure also. In this figure I want less data on both top and bottom (Important to show this also on graph) x-axis while in between the axises I want more data point. How Can I do this.
data = xlsread("hello.xlsx");
vel = data(:,1);
Min = data(:,3);
Mod = data(:,5);
Maj = data(:,7);
Col = data(:,9);
plot(vel,Min,'--k+', 'MarkerSize',7,'linewidth', 1.5,'MarkerIndices',1:3:length(vel))
hold on
plot(vel,Mod,'--bo', 'MarkerSize',7,'linewidth', 1.5,'MarkerIndices',1:4:length(vel))
plot(vel,Maj,'--gs', 'MarkerSize',7,'linewidth', 1.5,'MarkerIndices',1:5:length(vel))
plot(vel,Col,'--r*', 'MarkerSize',7,'linewidth', 1.5,'MarkerIndices',1:6:length(vel))
hold off
%grid on
Thanks in advance...

Akzeptierte Antwort

Antoni Garcia-Herreros
Antoni Garcia-Herreros am 29 Mär. 2023
You could try something like this:
data = xlsread("hello.xlsx");
vel = data(:,1);
Min = data(:,3);
Mod = data(:,5);
Maj = data(:,7);
Col = data(:,9);
step=20; %Sets the space between the non-important data
th=0.001; % Threshold to accept the minimum distance between consecutive points
Diff_Min=Min(1:numel(Min)-1,1)-Min(2:numel(Min),1); %Array storing the difference between consecutive points
i_Min_first=find(abs(Diff_Min)>th,1); % First index with a difference larger than the threshold
i_Min_last=find(abs(Diff_Min)>th,1,'last'); % Last index with a difference larger than the threshold
V_Min=[vel(1:step:i_Min_first);vel(i_Min_first+1:i_Min_last);vel(i_Min_last+1:step:end)]; %vel array with the values of the 3 regions
Y_Min=[Min(1:step:i_Min_first);Min(i_Min_first+1:i_Min_last);Min(i_Min_last+1:step:end)]; %Min array with the values of the 3 regions
plot(V_Min,Y_Min,'--k+', 'MarkerSize',7,'linewidth', 1.5)
hold on
plot(V_Mod,Y_Mod,'--bo', 'MarkerSize',7,'linewidth', 1.5)
plot(V_Maj,Y_Maj,'--gs', 'MarkerSize',7,'linewidth', 1.5)
plot(V_Col,Y_Col,'--r*', 'MarkerSize',7,'linewidth', 1.5)
hold off
  1 Kommentar
Raj Arora
Raj Arora am 29 Mär. 2023
Thanks antoni, I understood what you are doing, basically dividing each plot into 3 different sections and then plotting those. Initially I also thought in the same way but not able to implement it. Thanks once again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)


Mehr zu Visual Exploration 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!

Translated by