Creating individual coordinate variables from excel

5 views (last 30 days)
I am trying to write a code that inputs coordinate data from excel and stores each row of x,y,z coordinates into its own variable.
So far I have this which brings in all my data and stores into a matrix containing all three coordinate points.
[num,txt,raw] = xlsread('Excel.xlsx');
x = num(:,1);
y = num(:,2);
z = num(:,3);
p = [x, y, z];
I am unsure of how to extract each row in order to have each set of coordinate points be stored in its own x,y,z variable.
What I have:
p =
1.0e+06 *
1.744644127200000 -4.014801833900000 4.623258965200001
1.671483114500000 -3.987389898500000 4.673416349999999
What I would like:
Cooridnate 1 = 1.744644127200000 -4.014801833900000 4.623258965200001
Cooridnate 2 = 1.671483114500000 -3.987389898500000 4.673416349999999
There is also an unknown number of coordinates to consider.
Thank you very much!
Cris LaPierre
Cris LaPierre on 19 Jan 2022
I'd also suggest the following chapters in MATLAB Onramp.
  • Ch 4 - vectors and matrices
  • Ch 5 - Indexing into and modifying arrays and matrices
  • Ch 6 - array calculations
  • Ch 2 - programming (section 2 covers for loops)

Sign in to comment.

Answers (1)

Sailesh Kalyanapu
Sailesh Kalyanapu on 25 Jan 2022
You can extract the individual rows using a for loop and then use a cell array to store the rows individually. You can index the cell array to obtain desired rows later.
Please use the following code snippet for reference:
[num,txt,raw] = xlsread('Excel.xlsx');
[rowL,columnL] = size(num);
Coords_cellarray = {};
for i = 1:rowL
Coords_cellarray(i,:) = {num(i,:)} ;
%% To access the ith row extracted, you can use ith_row = Coords_cellarray{i};
Use of readtable, readmatrix, or readcell is recommended instead to read the xls file.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by