How can i make 3D graph with multiple 2D graphs?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens

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 commentaires
Réponse acceptée
Star Strider
le 13 Juin 2024
Modifié(e) : Star Strider
le 13 Juin 2024
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 commentaires
Star Strider
le 14 Juin 2024
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')
% 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)
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');
.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!










