필터 지우기
필터 지우기

How can i make 3D graph with multiple 2D graphs?

조회 수: 11 (최근 30일)
재훈
재훈 2024년 6월 13일
댓글: Star Strider 2024년 6월 14일
I made R0-SOC graph at various C values in 2D figure. Now, how can I make 3D figure about R0 for SOC,C values? Which makes me hard to figure it out is that 0.05C, 0.1C, 1/3C has 17 values and 1C and 2C have 13 values.
The output would look like this one.
Thank you for your help.

채택된 답변

Star Strider
Star Strider 2024년 6월 13일
편집: Star Strider 2024년 6월 13일
If the vectors all have the same sizes, just plot them as a matrix using the surf function.
t = linspace(0, 1, 25).'; % Assume Column Vectors
s = sin(t*[1:0.5:3]*2*pi) .* exp(-2.5*t);
figure
plot(t, s)
grid
figure
surfc((0:4), t, s)
grid on
colormap(turbo)
view(120,30)
EDIT — (13 Jun 2024 at 16:37)
Tweaked ‘s’ to add exponential decay, changed view of second figure. Code otherwise unchanged.
.
  댓글 수: 4
재훈
재훈 2024년 6월 14일
%% C_rate at Charge
load('data.mat')
a = find(C_rate==0.05 & Charge_Discharge==1);
b= find(C_rate==0.1 & Charge_Discharge==1);
c= find(C_rate== 0.333333333333333 & Charge_Discharge==1);
d=find(C_rate==1 & Charge_Discharge==1);
e=find(C_rate==2 & Charge_Discharge==1);
SOC_a=SOC(a);
R0_a=R0(a);
R1_a=R1(a);
C1_a=C1(a);
SOC_b=SOC(b);
R0_b=R0(b);
R1_b=R1(b);
C1_b=C1(b);
SOC_c=SOC(c);
R0_c=R0(c);
R1_c=R1(c);
C1_c=C1(c);
SOC_d=SOC(d);
R0_d=R0(d);
R1_d=R1(d);
C1_d=C1(d);
SOC_e=SOC(e);
R0_e=R0(e);
R1_e=R1(e);
C1_e=C1(e);
figure;
plot(SOC_a,R0_a,'b')
hold on;
plot(SOC_b,R0_b,'r')
hold on;
plot(SOC_c,R0_c,'g')
hold on;
plot(SOC_d,R0_d,'m')
hold on;
plot(SOC_e,R0_e,'k')
hold off;
xlabel('SOC[%]');
ylabel('R0[Ohm]');
legend('0.05C', '0.1C', '1/3C', '1C', '2C');
figure;
plot(SOC_a,R1_a,'b')
hold on;
plot(SOC_b,R1_b,'r')
hold on;
plot(SOC_c,R1_c,'g')
hold on;
plot(SOC_d,R1_d,'m')
hold on;
plot(SOC_e,R1_e,'k')
hold off;
xlabel('SOC[%]');
ylabel('R1[Ohm]');
legend('0.05C', '0.1C', '1/3C', '1C', '2C');
figure;
plot(SOC_a,C1_a,'b')
hold on;
plot(SOC_b,C1_b,'r')
hold on;
plot(SOC_c,C1_c,'g')
hold on;
plot(SOC_d,C1_d,'m')
hold on;
plot(SOC_e,C1_e,'k')
hold off;
xlabel('SOC[%]');
ylabel('C1[F]');
legend('0.05C', '0.1C', '1/3C', '1C', '2C');
I attached the code and the actual data.
The 2D plots is drawn with maybe option 2 or 3 that you mentioned. So 3D graph with those option would be good. 0.05C, 0.1C, 1/3C has 17 values and 1C and 2C have 13 values. Each vector is named as a,b,c,d,e.
I really appreciate your help!
Star Strider
Star Strider 2024년 6월 14일
My pleasure!
It took a few minutes to get this working as I want it to.
First, use loops. It’s just easier.
Second, I ended up interpolating between the largest minimum value and the smallest maximum value of ‘SOC’ to avoid extrapolating.
Third, I kept the number of extrapolation points at 17, the longest size of ‘SOC’. That meant creating a few extra data in the shorter vectors. To use the shortest vector instead, use:
lenmax = min(cellfun(@numel, SOCc));
No other changes in my code woiuld be necessary.
After that, it was just a matter of getting the surfc plots to look the way I want them to. You are of course free to change the surfc plot loop to make them the way you want them.
The code —
%% C_rate at Charge
load('data.mat')
whos('-file','data')
Name Size Bytes Class Attributes C1 163x1 1304 double C_rate 163x1 1304 double Charge_Discharge 163x1 1304 double R0 163x1 1304 double R1 163x1 1304 double SOC 163x1 1304 double
% a = find(C_rate==0.05 & Charge_Discharge==1);
% b= find(C_rate==0.1 & Charge_Discharge==1);
% c= find(C_rate== 0.333333333333333 & Charge_Discharge==1);
% d=find(C_rate==1 & Charge_Discharge==1);
% e=find(C_rate==2 & Charge_Discharge==1);
C_r = [0.05, 0.1, 0.333333333333333, 1, 2];
C_D = [1 1 1 1 1];
for k = 1:numel(C_r) % Data Extraction Loop
idxc{k} = find(C_rate == C_r(k) & Charge_Discharge == C_D(k));
SOCc{k} = SOC(idxc{k});
R0c{k} = R0(idxc{k});
R1c{k} = R1(idxc{k});
C1c{k} = C1(idxc{k});
end
ttls = ["R0[Ohm]","R1[Ohm]","C1[F]"];
xc = SOCc;
yc = {R0c; R1c; C1c};
for k1 = 1:numel(ttls) % 2-D Plot Loop
figure
hold on
for k2 = 1:numel(SOCc)
plot(xc{k2}, yc{k1}{k2})
end
hold off
xlabel('SOC[%]');
ylabel(ttls(k1));
title(ttls(k1))
grid
legend('0.05C', '0.1C', '1/3C', '1C', '2C');
end
lenmax = max(cellfun(@numel, SOCc));
[minxmin,minxmax] = bounds(cellfun(@min, SOCc));
[maxxmin,maxxmax] = bounds(cellfun(@max, SOCc));
xq = linspace(minxmax, maxxmin, lenmax);
for k1 = 1:numel(ttls) % Interpolation Loop, Creates Surface Matrices ('yq') As Well
for k2 = 1:numel(SOCc)
yq(:,k1,k2) = interp1(xc{k2}, yc{k1}{k2}, xq);
end
yq_name(k1) = ttls(k1);
end
Szyq = size(yq)
Szyq = 1x3
17 3 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
for k1 = 1:numel(ttls) % Surface Plot Loop
sp = squeeze(yq(:,k1,:));
figure
surfc(C_r, xq, sp) % Use 'surf' If You Do Not Need The Contour Plots
Ax = gca;
xlabel('C\_rate')
Ax.XTick = C_r;
Ax.XTickLabel = {'0.05C', '0.1C', '1/3C', '1C', '2C'};
Ax.XScale = 'log'; % Optional
ylabel('SOC[%]')
Ax.YDir = 'reverse';
zlabel(ttls(k1))
title(ttls(k1))
view(-45,30)
colormap(turbo)
colorbar
end
% SOC_a=SOC(a);
% R0_a=R0(a);
% R1_a=R1(a);
% C1_a=C1(a);
%
% SOC_b=SOC(b);
% R0_b=R0(b);
% R1_b=R1(b);
% C1_b=C1(b);
%
% SOC_c=SOC(c);
% R0_c=R0(c);
% R1_c=R1(c);
% C1_c=C1(c);
%
% SOC_d=SOC(d);
% R0_d=R0(d);
% R1_d=R1(d);
% C1_d=C1(d);
%
% SOC_e=SOC(e);
% R0_e=R0(e);
% R1_e=R1(e);
% C1_e=C1(e);
%
% figure;
% plot(SOC_a,R0_a,'b')
% hold on;
% plot(SOC_b,R0_b,'r')
% hold on;
% plot(SOC_c,R0_c,'g')
% hold on;
% plot(SOC_d,R0_d,'m')
% hold on;
% plot(SOC_e,R0_e,'k')
% hold off;
% xlabel('SOC[%]');
% ylabel('R0[Ohm]');
% legend('0.05C', '0.1C', '1/3C', '1C', '2C');
%
% x{1,1} = SOC_a
% y{1,1} = R0_a
%
%
% figure;
% plot(SOC_a,R1_a,'b')
% hold on;
% plot(SOC_b,R1_b,'r')
% hold on;
% plot(SOC_c,R1_c,'g')
% hold on;
% plot(SOC_d,R1_d,'m')
% hold on;
% plot(SOC_e,R1_e,'k')
% hold off;
% xlabel('SOC[%]');
% ylabel('R1[Ohm]');
% legend('0.05C', '0.1C', '1/3C', '1C', '2C');
%
% figure;
% plot(SOC_a,C1_a,'b')
% hold on;
% plot(SOC_b,C1_b,'r')
% hold on;
% plot(SOC_c,C1_c,'g')
% hold on;
% plot(SOC_d,C1_d,'m')
% hold on;
% plot(SOC_e,C1_e,'k')
% hold off;
% xlabel('SOC[%]');
% ylabel('C1[F]');
% legend('0.05C', '0.1C', '1/3C', '1C', '2C');
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by