Effacer les filtres
Effacer les filtres

Attach first column with names to matrix with coordinates

5 vues (au cours des 30 derniers jours)
Panos Kerezoudis
Panos Kerezoudis le 12 Avr 2023
Commenté : Jon le 12 Avr 2023
Hi!
I have a matrix ('positions') with 3 columns (x,y,z coordinates) and 200 rows (intracranial electodes).
I also have a character variable ('name') that contains an abbreviated name for each electrode. Is there a way to attach this column to the matrix, other than creating essentially a cell array? The goal is to ultimately export this matrix/dataset as an excel file (ie it will contain 4 columns and 200 row entries).
Thank you!

Réponse acceptée

Jon
Jon le 12 Avr 2023
Modifié(e) : Jon le 12 Avr 2023
You can put the data into a table, and assign row names
For example
x = rand(5,1);
y=rand(5,1);
z=rand(5,1);
names = {'cat','dog','fish','mouse','bird'};
T = table(x,y,z,'RowNames',names)
T = 5×3 table
x y z _______ ________ ________ cat 0.13646 0.65798 0.57989 dog 0.13375 0.44793 0.50756 fish 0.12136 0.43526 0.22403 mouse 0.26111 0.068975 0.063686 bird 0.22265 0.1669 0.29217
Then to put the table into Excel
writetable(T,'mydata.xlsx','WriteRowNames',1)
  2 commentaires
Panos Kerezoudis
Panos Kerezoudis le 12 Avr 2023
it worked, thank you!
Jon
Jon le 12 Avr 2023
You're welcome

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by