Plot 4d data

4 views (last 30 days)
Matthew Worker
Matthew Worker on 1 Oct 2019
Edited: N/A on 18 Jun 2021
hi :) how can one import an excel sheet with x, y, z and V columns as a 3d matrix? I am trying to plot the V values over a co ordiante system (using slice function) .
Thanks!

Answers (1)

Joe Vinciguerra
Joe Vinciguerra on 1 Oct 2019
May not be the most efficient, but this is what I came up with:
Here's my sample data based on my interpretation of your description:
Capture.JPG
% Load the data from the source file
[filename, pathname] = uigetfile('*.xls*','MultiSelect','off'); % open file selection dialog
ScriptFolder = cd(pathname); % change to the folder location you selected so you can read the file
A = readmatrix(filename); % read the file you selected
% assign to seperate variables for clarity
x = A(:,1);
y = A(:,2);
z = A(:,3);
% build a multidimensional array (again, may not be the most efficient approach)
% https://www.mathworks.com/help/matlab/math/multidimensional-arrays.html
for i=1:length(A)
V(x(i),y(i),z(i)) = A(i,4);
end
% plot using the slice function
% https://www.mathworks.com/help/matlab/ref/slice.html
xslice = [1,2,3];
yslice = [];
zslice = [2];
slice(V,xslice,yslice,zslice)
untitled.jpg

Categories

Find more on Data Import from MATLAB 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!