Plot values of 3D matrix against a single variable

2 vues (au cours des 30 derniers jours)
Evagoras Kassapis
Evagoras Kassapis le 13 Oct 2021
Commenté : Image Analyst le 14 Oct 2021
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.

Réponse acceptée

Image Analyst
Image Analyst le 13 Oct 2021
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 commentaires
Evagoras Kassapis
Evagoras Kassapis le 14 Oct 2021
Modifié(e) : Evagoras Kassapis le 14 Oct 2021
Yes, thank you for this, works great. How can I get it to be one line plot, like one pressure line vs frequency. Do I average the pressures at each frequency and then plot it?
Image Analyst
Image Analyst le 14 Oct 2021
Yes.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots 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!

Translated by