フィルターのクリア

find the values ​​in the row and column of the matrix by using the loop

3 ビュー (過去 30 日間)
busra dogru
busra dogru 2019 年 4 月 11 日
コメント済み: Star Strider 2019 年 4 月 12 日
I have a matrix that consists of multiple rows and columns in a text file. I want to use the value in each row as x, the value in each column as y. How can I do this using a loop? Thanks in advance ..
  2 件のコメント
madhan ravi
madhan ravi 2019 年 4 月 11 日
Upload your file
busra dogru
busra dogru 2019 年 4 月 11 日
okey.

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

回答 (2 件)

madhan ravi
madhan ravi 2019 年 4 月 12 日
datas=dlmread('Mymatrix.txt');
x=datas(:,1);
y=datas(:,2);
  1 件のコメント
busra dogru
busra dogru 2019 年 4 月 12 日
Thank you for your answer. It was very helpful.

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


Star Strider
Star Strider 2019 年 4 月 12 日
Your ‘y’ values are not unique for each ‘x’ value.
If you want all the ‘y’ values for each ‘x’ value, this works:
D = load('Mymatrix.txt');
x = D(:,1);
y = D(:,2);
xyMtx = accumarray(x, y, [], @(x){x}); % All ‘y’ Values For Each ‘x’ Value
producing (for example):
x_1 = [xyMtx{1}] % ‘y’ Values For ‘x = 1’
x_3 = [xyMtx{3}] % ‘y’ Values For ‘x = 3’
x_20 = [xyMtx{20}] % ‘y’ Values For ‘x = 20’
that evaluate to:
x_1 =
2
93
x_3 =
1
2
3
92
93
94
x_20 =
4
5
6
89
90
91
Is that what you want?
  2 件のコメント
busra dogru
busra dogru 2019 年 4 月 12 日
Yeah. Many thanks for your reply.
Star Strider
Star Strider 2019 年 4 月 12 日
My pleasure.
It is relatively easy to do the reverse as well, that is to return all the x-values associated with every y-value.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by