36 views (last 30 days)
Show older comments
재훈 on 13 Jun 2024 at 14:35
-
-
Link
Direct link to this question
https://matlabcentral.mathworks.com/matlabcentral/answers/2128366-how-can-i-make-3d-graph-with-multiple-2d-graphs
Commented: Star Strider on 14 Jun 2024 at 6:31
Accepted Answer: Star Strider
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.
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Star Strider on 13 Jun 2024 at 15:01
Edited: Star Strider on 13 Jun 2024 at 16:37
Open in MATLAB Online
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 Comments Show 2 older commentsHide 2 older comments
Show 2 older commentsHide 2 older comments
재훈 on 14 Jun 2024 at 0:24
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/2128366-how-can-i-make-3d-graph-with-multiple-2d-graphs#comment_3186266
Thanks, but the problem is that the verctors have differrnt sizes...
Star Strider on 14 Jun 2024 at 0:45
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/2128366-how-can-i-make-3d-graph-with-multiple-2d-graphs#comment_3186291
Then there are three options, both requiring interpolation using the interp1 function.
- Interpolate them to the size of the independent variable size of the shortest vector.
- Interpolate them to the independent varriable size of the longest vector
- Interpolate all of them to a completely different independent variable vector
The first option would eliminate some values of the longer dependent variable. The second option would create data in the shorter dependent variable vector where no data previously existed. The third optioon combines some or all of these problems, depending on what the interpolating vector is.
Withbout the actual data, I cannot write any specific code. If you provide the data, I can code for as many of these options as you choose, and you can decide which you prefer.
.
재훈 on 14 Jun 2024 at 2:02
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/2128366-how-can-i-make-3d-graph-with-multiple-2d-graphs#comment_3186321
Open in MATLAB Online
- data.mat
%% 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 on 14 Jun 2024 at 6:31
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/2128366-how-can-i-make-3d-graph-with-multiple-2d-graphs#comment_3186446
Open in MATLAB Online
- data.mat
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');
.
Sign in to comment.
More Answers (0)
Sign in to answer this question.
See Also
Tags
- 3d plots
- interpolation
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office