How can i make 3D graph with multiple 2D graphs?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示

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
2024 年 6 月 13 日
編集済み: Star Strider
2024 年 6 月 13 日
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 日
Thanks, but the problem is that the verctors have differrnt sizes...
Star Strider
2024 年 6 月 14 日
- 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.
.
재훈
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!
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 件)
カテゴリ
ヘルプ センター および File Exchange で Line Plots についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- 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
- United Kingdom (English)
