plotting a 2D line plot using data with 3 variables

Hi,
Could anyone tell me how to best go about plotting a line graph when the y axis data has 3 variables (100x14x24000 [depth x sediment diameter x concentration]) I need to be able to adjust the first 2 variables as will be plotting under different conditions.
any help would be greatly appreciated.

답변 (1개)

Voss
Voss 2022년 1월 23일
Is something like this what you want to do?
% 100 depth values:
depth = 100:199;
% 14 sediment diameter values:
diameter = linspace(1,2,14);
% some data 100x140x24000
data = depth.'+10*diameter+cosd(permute(1:24000,[3 1 2])/10);
% normalized to [0,1] (like concentrations)
data = (data-min(data(:)))/(max(data(:))-min(data(:)));
% pick a few values to plot
depth_idx_to_plot = [1 50 100];
diameter_idx_to_plot = [1 4 7 10 13];
% plot the lines
figure();
hold on
Ndepth = numel(depth_idx_to_plot);
Ndiameter = numel(diameter_idx_to_plot);
names = cell(1,Ndepth*Ndiameter);
for i = 1:Ndepth
for j = 1:Ndiameter
plot(squeeze(data(depth_idx_to_plot(i),diameter_idx_to_plot(j),:)));
names{Ndiameter*(i-1)+j} = sprintf('Conc @ (Z=%g,D=%.2f)',depth(depth_idx_to_plot(i)),diameter(diameter_idx_to_plot(j)));
end
end
legend(names,'Location','EastOutside')

댓글 수: 2

Hi Benjamin,
Thank you for your answer, and apologies but i am still getting to grips with matlab.
What i am trying to do is set the input for the second element.
when i apply a squeeze I have been able to remove one of variables and plot it like this with a rows of depths being selected independantly
  1. plot(t,SGSdata_2m.Cg(1,:),'k','DisplayName','2m_Cg','linewidth',2) %5m
  2. plot(t,SGSdata_2m.Cg(32,:),'k','DisplayName','2m_Cg','linewidth',2) %4.2m
  3. plot(t,SGSdata_2m.Cg(42,:),'k','DisplayName','2m_Cg','linewidth',2) %3.5m
but what i want to be able to do is same as above, but also include the middle variable something like (1,: 8,:)
So SGSdata_2m.Cg is the output from squeeze(), right? Is it size 100x24000? And it has been generated by selecting one value for sediment diameter, is that correct? Something like this:
d_idx = 14;
SGSdata_2m.Cg = squeeze(original_full_data_set(:,d_idx,:));
Is that basically what you mean? If so, then to plot some values for some other sediment diameter, you'd have to go back to the un-squeeze()'d data. For example, to plot the data at the 1st depth and 8th sediment diameter, you could say:
plot(t,squeeze(original_full_data_set(1,8,:)),'k','DisplayName','2m_Cg','linewidth',2)
If that's not what you have in mind, please explain further, and consider posting (a subset of) your data and more of your code.

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

카테고리

도움말 센터File Exchange에서 Just for fun에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 1월 22일

댓글:

2022년 1월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by