Is there a way to create a lot of graphs for a 4D matrix without coding for a ton of individual graphs?

I have a 4D matrix that I'm trying to create graphs for. There are 4 dimensions, a physical state, two informational states, and time.
I want to make a bunch of graphs within a larger "graph" Basically info state 1 on the y axis and info state 2 on the x axis, but then within that, there are a bunch of graphs with physical state on the y axis and time on the x axis.
Here's an example of one graph:
fivexfive(:,:)=opt(:,5,5,:);
imagesc(fivexfive);
colorbar;
xlabel('Time');
ylabel('State');
set(gca,'YDir','normal');
axis('square')
the second two dimensions range from 1-15 each. So that'd be..... a lot of graphs.
Is there any way to try and make at least a few of them without brute forcing a ton of graphs? If that's not possible that's fine, figured I'd try asking!

5 Comments

you can certainly script graph creating and automate the process. is that all you're seeking?
if that's the case, you just need to iterate acreoss those dimensions, probably something like:
for i1=1:size(matrix,2)
for i2=1:size(matrix,3)
currentGraph=opt(:,i1,i2,:);
imagesc(currentGraph);
colorbar;
xlabel('Time');
ylabel('State');
set(gca,'YDir','normal');
axis('square')
-> insert line for saving graph/figure however you want
end
end
Make a for loop and iterate through the varying values corresponding to your objective to make the plots.
"I want to make a bunch of graphs within a larger "graph""
You can use tiledlayout for that.
how would I use tiledlayout with a bunch of graphs created by a for loop? All of the smaller graphs correspond to specific positions on the xy axes on the larger graph, I don't want them just anywhere.
@Josh I'm having trouble with "Color data must be an m-by-n-by-3 or m-by-n matrix." and also getting " hh = image(varargin{:}, 'CDataMapping', 'scaled');"
That means that its trying to map out the four dimensions, right?
I tried editing it turning current graph into two dimensions like I had previously
currentgraph(:,:)=opt(:,i1,i2,:)
but that didn't seem to help at all

Sign in to comment.

 Accepted Answer

Hi Kitt,
Here is one approach. In the example you are using imagsc plots instead of e.g. 1d plots of some state quantity vs. time, so imagesc is used here. This code thinks about it for a few seconds and then makes 15 figures of 15 miniplots each, one of which is below.
A = rand(100,15,15,100); % assuming the order is state,info1,info2,time
B = permute(A,[4 1 2 3]); % put into an easier order, less potential problems for Matlab
for info1 = 1:15
figure(info1)
sgtitle(['inf01 = ' num2str(info1)])
info2 = 1;
subplot(4,4,info2)
imagesc(B(:,:,info1,info2))
title(['info2: ' num2str(info2)])
for info2 = 2:15
subplot(4,4,info2)
imagesc(B(:,:,info1,info2))
title(num2str(info2))
end
end

2 Comments

Oh wow that totally worked and now I can actually visualize my data!!!! Thank you so much I think this works for now :)
you're quite welcome. Matlab does have some useful plotting options.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!