Plot values of 3D matrix against a single variable

2 visualizaciones (últimos 30 días)
Evagoras Kassapis
Evagoras Kassapis el 13 de Oct. de 2021
Comentada: Image Analyst el 14 de Oct. de 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.

Respuesta aceptada

Image Analyst
Image Analyst el 13 de Oct. de 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 comentarios
Evagoras Kassapis
Evagoras Kassapis el 14 de Oct. de 2021
Editada: Evagoras Kassapis el 14 de Oct. de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by