# Creating individual coordinate variables from excel

5 views (last 30 days)
Janica Johnson on 19 Jan 2022
Answered: Sailesh Kalyanapu on 25 Jan 2022
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.
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 *
X Y Z
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 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)

Sailesh Kalyanapu on 25 Jan 2022
Hi,
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:
[rowL,columnL] = size(num);
Coords_cellarray = {};
for i = 1:rowL
Coords_cellarray(i,:) = {num(i,:)} ;
end
%% To access the ith row extracted, you can use ith_row = Coords_cellarray{i};
Hope this helps!

### Categories

Find more on Matrix Indexing 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!

Translated by