Info

此问题已关闭。 请重新打开它进行编辑或回答。

How to make this figure more simple with 'for'

1 次查看(过去 30 天)
I made some figure. But I want to make more simple this. But it's hard for me to make that.
could you help me?
And other problem is when I run this.
7Hz and 6Hz are plotted in one figure.
But 7Hz and 6Hz are isolated.
I appreciate you if you help me...
% everything_7Hz
aa=0;
v1 = v_t(1:1250,1+aa)*1000;
v2 = v_t(1:1250,2+aa)*1000;
v3 = v_t(1:1250,3+aa)*1000;
v4 = v_t(1:1250,4+aa)*1000;
v5 = v_t(1:1250,5+aa)*1000;
f1 = f_t(1+delay(1+aa):1250+delay(1+aa),1+aa);
f2 = f_t(1+delay(2+aa):1250+delay(2+aa),2+aa);
f3 = f_t(1+delay(3+aa):1250+delay(3+aa),3+aa);
f4 = f_t(1+delay(4+aa):1250+delay(4+aa),4+aa);
f5 = f_t(1+delay(5+aa):1250+delay(5+aa),5+aa);
dk1 = dk_t(1+delay(1+aa):1250+delay(1+aa),1+aa)*1000;
dk2 = dk_t(1+delay(2+aa):1250+delay(2+aa),2+aa)*1000;
dk3 = dk_t(1+delay(3+aa):1250+delay(3+aa),3+aa)*1000;
dk4 = dk_t(1+delay(4+aa):1250+delay(4+aa),4+aa)*1000;
dk5 = dk_t(1+delay(5+aa):1250+delay(5+aa),5+aa)*1000;
subplot(1,2,1);
plot(v1,f1, 'Linewidth',1.0 )
hold on
plot(v2,f2,'Linewidth',1.0, 'Linestyle','-.')
plot(v3,f3,'Linewidth',1.0, 'Linestyle','-')
plot(v4,f4,'Linewidth',1.0, 'Linestyle',':')
plot(v5,f5, 'Linewidth',1.0)
xlabel('Velocity (mm/s)')
ylabel('Force (N)')
box on
legend({'0.0 V', '0.5 V', '1.0 V', '1.5 V', '2.0 V'},'FontSize',8)
subplot(1,2,2);
plot(dk1,f1,'Linewidth',1.0)
hold on
plot(dk2,f2,'Linewidth',1.0,'Linestyle','-.')
plot(dk3,f3,'Linewidth',1.0,'Linestyle','-')
plot(dk4,f4,'Linewidth',1.0,'Linestyle',':')
plot(dk5,f5,'Linewidth',1.0)
xlabel('Displacement (mm)')
ylabel('Force (N)')
box on
legend({'0.0 V', '0.5 V', '1.0 V', '1.5 V', '2.0 V'},'FontSize',8)
% everything_6Hz
aa=5;
v1 = v_t(1:1250,1+aa)*1000;
v2 = v_t(1:1250,2+aa)*1000;
v3 = v_t(1:1250,3+aa)*1000;
v4 = v_t(1:1250,4+aa)*1000;
v5 = v_t(1:1250,5+aa)*1000;
f1 = f_t(1+delay(1+aa):1250+delay(1+aa),1+aa);
f2 = f_t(1+delay(2+aa):1250+delay(2+aa),2+aa);
f3 = f_t(1+delay(3+aa):1250+delay(3+aa),3+aa);
f4 = f_t(1+delay(4+aa):1250+delay(4+aa),4+aa);
f5 = f_t(1+delay(5+aa):1250+delay(5+aa),5+aa);
dk1 = dk_t(1+delay(1+aa):1250+delay(1+aa),1+aa)*1000;
dk2 = dk_t(1+delay(2+aa):1250+delay(2+aa),2+aa)*1000;
dk3 = dk_t(1+delay(3+aa):1250+delay(3+aa),3+aa)*1000;
dk4 = dk_t(1+delay(4+aa):1250+delay(4+aa),4+aa)*1000;
dk5 = dk_t(1+delay(5+aa):1250+delay(5+aa),5+aa)*1000;
subplot(1,2,1);
plot(v1,f1, 'Linewidth',1.0 )
hold on
plot(v2,f2,'Linewidth',1.0, 'Linestyle','-.')
plot(v3,f3,'Linewidth',1.0, 'Linestyle','-')
plot(v4,f4,'Linewidth',1.0, 'Linestyle',':')
plot(v5,f5, 'Linewidth',1.0)
xlabel('Velocity (mm/s)')
ylabel('Force (N)')
box on
legend({'0.0 V', '0.5 V', '1.0 V', '1.5 V', '2.0 V'},'FontSize',8)
subplot(1,2,2);
plot(dk1,f1,'Linewidth',1.0)
hold on
plot(dk2,f2,'Linewidth',1.0,'Linestyle','-.')
plot(dk3,f3,'Linewidth',1.0,'Linestyle','-')
plot(dk4,f4,'Linewidth',1.0,'Linestyle',':')
plot(dk5,f5,'Linewidth',1.0)
xlabel('Displacement (mm)')
ylabel('Force (N)')
box on
legend({'0.0 V', '0.5 V', '1.0 V', '1.5 V', '2.0 V'},'FontSize',8)
  2 个评论
Jan
Jan 2019-3-4
What does this mean:
7Hz and 6Hz are plotted in one figure. But 7Hz and 6Hz are isolated.
? If you provide some input, we could run your code. Is "v_t" a vector or a function?
CHOI HYUNDUK
CHOI HYUNDUK 2019-3-5
That is, I want to devide into two plot not one plot that has 7Hz and 6Hz.

回答(1 个)

Jan
Jan 2019-3-6
编辑:Jan 2019-3-6
Remember that the readers can read the question only, but not your mind. I cannot guess, what you want to divide into what. The details "6Hz" and "7Hz" occur in the code only as a comment "% everything_6Hz". Maybe all you want is to replace the subplot calls to:
subplot(2,2,1); % Instead of: subplot(1,2,1)
to move the last diagrams to specific axes.
By the way, your code would be much nicer, if you use a loop instead of hiding indices in the names of the variables:
LineStyleList = {'-', '--', '.-', ':', 'none'};
NameList = {'0.0 V', '0.5 V', '1.0 V', '1.5 V', '2.0 V'};
aaList = [0, 5];
for iaa = 1:numel(aa)
aa = aaList(iaa);
sub = (iaa - 1) * 2 + 1;
AxesH = [subplot(2, 2, sub, ...
'NextPlot', 'add', 'Box', 'on'), % Implicit: hold on, box on
subplot(2, 2, sub + 1, ...
'NextPlot', 'add', 'Box', 'on')];
for k = 1:5
v = v_t(1:1250, k + aa) * 1000;
f = f_t(1 + delay(k + aa):1250+delay(k + aa), k + aa);
dk = dk_t(1 + delay(k + aa):1250+delay(k + aa), k + aa) * 1000;
plot(AxesH(1), v, f, 'LineStyle', LineStyleList{k});
plot(AxesH(2), dk, f, 'LineStyle', LineStyleList{k});
end
xlabel(AxesH, 'Velocity (mm/s)');
ylabel(AxesH, 'Force (N)')
legend(AxesH, NameList, 'FontSize', 8);
end
So if you start with this, what do you want to modify?

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by