How to save Data Individually

I Have a Data
like 2000*5 i.e 2000 rows with 5 colomns.
I would like to save this the data in to five varaible like x1,x2,x3,x4 and x5 where x1 consisting of 1st coloms of x.
The MATLAB code must be any loop function.How to Write and save 2000*1 data of 5 different variables using a loop statement with MATLAB

2 Commenti

Stephen23
Stephen23 il 9 Feb 2022
Modificato: Stephen23 il 9 Feb 2022
"I would like to save this the data in to five varaible like x1,x2,x3,x4 and x5"
That is very unikely to be a good approach:
You can simply access the data directly from the matrix using basic indexing, or split the matrix into a cell array:
C = num2cell(M,1)
C PRASAD
C PRASAD il 15 Feb 2022
Thanks for the answe

Accedi per commentare.

Risposte (1)

Addy
Addy il 9 Feb 2022

0 voti

For the reason @Stephen mentioned. Only way to create variables in a loop is using eval function.
It is bad to use eval to create variables in loop.
So, you can do it manually like
x1 = x(:,1);
x2 = x(:,2);
....
Or in a loop to store in a cell
for i=1:size(x,2)
x_cell{:,i} = x(:,i);
end
Or just use num2cell
x_cell = num2cell(x,1);

3 Commenti

C PRASAD
C PRASAD il 11 Feb 2022
Thanks for the Answer,But This is my data in data_beffer1,it is of 8000*5 size .Now I would like to give name to each column where size of the each column must be 8000*1 size with loop statement
"Now I would like to give name to each column..."
Then use a table:
M = rand(8000,5);
T = array2table(M, 'VariableNames',{'a','b','c','hello','world'})
T = 8000×5 table
a b c hello world _________ ________ ________ ________ ________ 0.29025 0.1223 0.49279 0.34924 0.9614 0.56472 0.71979 0.79971 0.28213 0.48654 0.049005 0.90739 0.38714 0.56751 0.56329 0.5461 0.49098 0.9208 0.47405 0.2342 0.40111 0.28172 0.8404 0.39891 0.53901 0.13418 0.56801 0.2039 0.019276 0.52889 0.52612 0.74784 0.96346 0.43849 0.67462 0.018373 0.070646 0.29265 0.7457 0.52281 0.69947 0.29329 0.65923 0.4547 0.014092 0.31798 0.27716 0.97755 0.61423 0.67483 0.0048459 0.46726 0.035125 0.24189 0.90291 0.67208 0.825 0.68594 0.98525 0.2302 0.85427 0.79711 0.87272 0.98439 0.29113 0.85162 0.9343 0.22138 0.10056 0.31589 0.077557 0.95805 0.21503 0.80634 0.069713 0.43137 0.78357 0.16262 0.80901 0.37363
C PRASAD
C PRASAD il 15 Feb 2022
Thanks for the answer

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

il 9 Feb 2022

Commentato:

il 15 Feb 2022

Community Treasure Hunt

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

Start Hunting!

Translated by