plotting a 2D line plot using data with 3 variables

3 views (last 30 days)
Michael Cooper
Michael Cooper on 22 Jan 2022
Commented: _ on 24 Jan 2022
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.

Answers (1)

_ on 23 Jan 2022
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
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
names{Ndiameter*(i-1)+j} = sprintf('Conc @ (Z=%g,D=%.2f)',depth(depth_idx_to_plot(i)),diameter(diameter_idx_to_plot(j)));
_ on 24 Jan 2022
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:
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.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!