Plot values of 3D matrix against a single variable

3 次查看(过去 30 天)
I have a 4D matrix (4x4x4x6), the first three dimensions are the pressure at each of the x,y,z points in a space. The fourth dimension is the frequencies used to calculate the pressure. I want to plot the frequency response of the space. That means plot all the pressures against the frequency used to calculate them.

采纳的回答

Image Analyst
Image Analyst 2021-10-13
Try this:
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 17;
pressure = rand(4, 4, 4, 6); % Random data
[rows, columns, slices, freq] = size(pressure)
% Plot all pressure profiles for each (x,y,z) point.
for row = 1 : rows
for col = 1 : columns
for z = 1 : slices
% Get frequency response over all locations
p = squeeze(pressure(row, col, z, :))
% Plot this set of pressures for this particular (x,y,z) location:
plot(p, 'LineWidth', 2);
if row == 1 & col == 1 && z == 1
grid on;
xlabel('Frequency', 'FontSize', fontSize)
ylabel('Pressure', 'FontSize', fontSize)
hold on;
end
end
end
end
  2 个评论

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by