How can i make 3D graph with multiple 2D graphs?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천

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...
- 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.
.
%% 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에서 Axis Labels에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
