Plot values of 3D matrix against a single variable
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Evagoras Kassapis
am 13 Okt. 2021
Kommentiert: Image Analyst
am 14 Okt. 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.
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 13 Okt. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!