how to use elements from array to sort data

2 ビュー (過去 30 日間)
Sumanth
Sumanth 2023 年 2 月 27 日
コメント済み: Stephen23 2023 年 2 月 27 日
numdata = xlsread("res Data.xlsx");
1500 1500 500 1500 500 2500
850 850 200 850 200 1000
2800 2800 1700 2800 1700 5200
500 500 300 500 300 3000
1600 1600 1000 1600 1000 2700
10 9 10 11 10 9
9 9 9 10 9 9
13 11 13 12 13 11
21 18 21 20 21 18
18 18 18 19 18 18
for i = 1:6
Q(i) = numdata(1:5,i);
end
for i = 1:6
F(i) = numdata(6:10,i);
end
Hello I want to store a part of the array with some other name like I want Q1 = 1500 850 2800 500 1600
then Q2 = 1500 850 2800 500 1600 and so on..
and F1 = 10 9 13 21 18 and so on..
i get an error of incompatible size. Please help mein how to handle big data from excel sheets to store data appropriately.
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 2 月 27 日
編集済み: Dyuman Joshi 2023 年 2 月 27 日
"I want Q1 = 1500 850 2800 500 1600 then Q2 = 1500 850 2800 500 1600 and so on.. and F1 = 10 9 13 21 18 and so on.."
What you want to do is incredibly inefficient and difficult to work with. Read more here
You already have the data in matrices, you can access them via indexing, in an easy, efficient and clear manner.

サインインしてコメントする。

採用された回答

Kevin Holly
Kevin Holly 2023 年 2 月 27 日
編集済み: Kevin Holly 2023 年 2 月 27 日
numdata = [1500 1500 500 1500 500 2500;
850 850 200 850 200 1000;
2800 2800 1700 2800 1700 5200;
500 500 300 500 300 3000;
1600 1600 1000 1600 1000 2700;
10 9 10 11 10 9;
9 9 9 10 9 9;
13 11 13 12 13 11;
21 18 21 20 21 18;
18 18 18 19 18 18];
for i = 1:6
Q(i,:) = numdata(1:5,i);
end
The variable in this case is a matrix. Is it fine if it is this way in stead of individual variables called Q1,Q2? If this is need,
Q(1,:)
ans = 1×5
1500 850 2800 500 1600
Q(2,:)
ans = 1×5
1500 850 2800 500 1600
If this is needed, then you could use assignin.
assignin('base','Q1',Q(1,:))
Q1
Q1 = 1×5
1500 850 2800 500 1600
for i = 1:6
F(i,:) = numdata(6:10,i);
end
F(1,:)
ans = 1×5
10 9 13 21 18
F(2,:)
ans = 1×5
9 9 11 18 18
If you are dealing with large data and this was just a sample dataset, I would recommend using spreadsheetdatastore and tall arrays.
ssds = spreadsheetDatastore(location,"FileExtensions",[".xlsx",".xls"]) ;
tt = tall(ssds)
  2 件のコメント
Kevin Holly
Kevin Holly 2023 年 2 月 27 日
編集済み: Kevin Holly 2023 年 2 月 27 日
If you want it in a for loop:
numdata = [1500 1500 500 1500 500 2500;
850 850 200 850 200 1000;
2800 2800 1700 2800 1700 5200;
500 500 300 500 300 3000;
1600 1600 1000 1600 1000 2700;
10 9 10 11 10 9;
9 9 9 10 9 9;
13 11 13 12 13 11;
21 18 21 20 21 18;
18 18 18 19 18 18];
for i = 1:6
assignin('base',['Q' num2str(i)],numdata(1:5,i)')
end
Q1
Q1 = 1×5
1500 850 2800 500 1600
Q2
Q2 = 1×5
1500 850 2800 500 1600
Q3
Q3 = 1×5
500 200 1700 300 1000
Q4
Q4 = 1×5
1500 850 2800 500 1600
Q5
Q5 = 1×5
500 200 1700 300 1000
Q6
Q6 = 1×5
2500 1000 5200 3000 2700
Sumanth
Sumanth 2023 年 2 月 27 日
Thank you this helps a lot!

サインインしてコメントする。

その他の回答 (2 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 2 月 27 日
Here is the corrected code:
numdata=readmatrix("res Data.xlsx");
Q = numdata(1:5, :)';
F = numdata(6:10, :)';

David Hill
David Hill 2023 年 2 月 27 日
Keep your data stored in matrices that you can index into.
numdata = xlsread("res Data.xlsx");
Q=numdata(1:5,:);
F=numdata(6:10,:);
Q1=Q(:,1);Q2=Q(:,2);%whenever you want them Q(:,n)
  2 件のコメント
Sumanth
Sumanth 2023 年 2 月 27 日
Can we not write a for loop for putting it From Q1 to Q6??
Stephen23
Stephen23 2023 年 2 月 27 日
"Can we not write a for loop for putting it From Q1 to Q6??"
Sure, if you really want to make accessing your data slow, complex, and inefficient:

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by