How to add a verteical pad obove and below the curve and graph style and color displays?

1 ビュー (過去 30 日間)
Nisar Ahmed
Nisar Ahmed 2022 年 6 月 1 日
回答済み: Mathieu NOE 2022 年 6 月 3 日
I have two questions and the data is attached to the question:
Q1) Lest hand side code is for the figure on right hand side. How I can the color of each curve and curve style (dotted, asterisk, etc.) by myself in the code instead of MATLAB is chossing automatically?
Q2) In the figure on right hand side, qp at various f are plotted against VD. I have attached a data having VD and one of qp curve. the qp curves not of same length of VD. I want to add a pad above and below the qp curves such that it becomes equal to VD. The pad values should be between 0.001 to 0.002. How I can do it?
  8 件のコメント
Nisar Ahmed
Nisar Ahmed 2022 年 6 月 1 日
Here is the data in which qp or Inv Q is a 2D matrix.


回答 (2 件)

Hiro 2022 年 6 月 1 日
Solution 1:
You can control the order of color by using colororder.
Also, you can specify the line markers by like this.
Solution 2:
How about re-sampling the VD with interp1 so you can have the identical length for that vector?
  1 件のコメント
Nisar Ahmed
Nisar Ahmed 2022 年 6 月 1 日
Thank you for the comments,
In the figure code, it is loop here so how to specify the colororder or markers is not working
hold on
for kk = 1:10:600
plot(Inv_Q(:,kk),VD, 'DisplayName',sprintf('f = %d',f(kk)))
hold off
legend('Location','best'); set(gca, 'ydir', 'reverse');
xlim([0 3.0e-2]); ylim([1.8879e+03 2.1313e+03]);
xlabel('qp'); ylabel('VD');
2) I do not need to interploate, istead I need to add pad above and below until both matrices become equal.


Mathieu NOE
Mathieu NOE 2022 年 6 月 3 日
hello Nisar
this is my suggestion , and result
your last mat file does not contain the f data so I skipped that portion of code for the time being - should be fairly easy to reactivate it on your side
here a demo with a spacing of 5 netween succesive data (your original code was with a spacing of 10)
[m,n] = size(Inv_Q);
%% define your custom color order
% option 1 : manually : possible but takes time and not flexible / robust
% colors = [0 0 1;...
% 0 1 0;...
% 1 0 0;...
% 0 1 1;...
% 1 0 1;...
% 1 0.69 0.39;...
% 0.6 0.2 0;...
% 0 0.75 0.75;...
% 0.22 0.44 0.34;...
% 0.32 0.19 0.19]; %10x3 RGB array
% % or based on existing color maps
% colors = jet(n);
% or this
% %
% colors = linspecer(60);
% even better :
func = @(x) colorspace('RGB->Lab',x); %
colors = distinguishable_colors(n,{'w','k'},func); %
%% define line styles and loop over them
linS = {'-','--',':','-.'};
hold on
c = 0;
cc = c;
new_x = linspace(min(VD1),max(VD1),m);
for kk = 1:5:n
c= c+1;
cc = cc+1;
if cc>length(linS)
cc = 1 ; % restart from 1
plot(Inv_Q(:,kk),new_x,'Color',colors(c,:),'linestyle',linS{cc}); % plot(Inv_Q(:,kk),VD1, 'DisplayName',sprintf('f = %d',f(kk)))
leg_str{c} = (['Data ' num2str(kk)]);
hold off
legend(leg_str,'Location','best'); set(gca, 'ydir', 'reverse');
xlim([0 3.0e-2]); ylim([1.8879e+03 2.1313e+03]);
xlabel('qp'); ylabel('VD');

Community Treasure Hunt

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

Start Hunting!

Translated by