How to save Data Individually

조회 수: 1 (최근 30일)
C PRASAD
C PRASAD 2022년 2월 9일
댓글: C PRASAD 2022년 2월 15일
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
Stephen23
Stephen23 2022년 2월 9일
편집: Stephen23 2022년 2월 9일
"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 2022년 2월 15일
Thanks for the answe

댓글을 달려면 로그인하십시오.

답변 (1개)

Addy
Addy 2022년 2월 9일
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
Stephen23
Stephen23 2022년 2월 11일
편집: Stephen23 2022년 2월 11일
"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 2022년 2월 15일
Thanks for the answer

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by