Calling text file in matlab

1 回表示 (過去 30 日間)
muhammad ismat
muhammad ismat 2015 年 6 月 9 日
コメント済み: muhammad ismat 2015 年 6 月 14 日
if i have text file that has three column say
1 2 1
3 1 1
2 3 1
and also have a matrix s =
[0.3 0.4 0.6
0.1 0.5 0.7
0.2 0.11 0.9]
firstly: with respect to text file, i want to consider first column as i and second column as j then if the third column equal 1 then put its corresponding value in matrix s in new array say A else put remaining value in matrix s in new another array say B.
i.e i want this result
A=[0.4, 0.2, 0.7] B=[0.3, 0.6, 0.1, 0.5, 0.11, 0.9]
  2 件のコメント
Guillaume
Guillaume 2015 年 6 月 9 日
Where do the values go if the third column is not 1? At present your rule is:
coordinate is present and third column is 1 -> put in A
coordinate not present -> put in B
what is the rule for
coordinate is present and third column is not 1 -> ??
muhammad ismat
muhammad ismat 2015 年 6 月 14 日
i'm so sorry for more questions
we consider the coordinates that present are 1 2, 2 1,3 1, 1 3,2 3,3 2; i.e that present and its inverse so A=[0.4 , 0.1 , 0.2 , 0.6 , 0.7, 0.11] B=[0.3, 0.5, 0.9]
2- how to take percentage of variable A say 20% of values

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2015 年 6 月 9 日
編集済み: Andrei Bobrov 2015 年 6 月 9 日
ii = [1 2 1
3 1 1
2 3 1];
s = [0.3 0.4 0.6
0.1 0.5 0.7
0.2 0.11 0.9];
[x,y,z] = size(s);
ij = num2cell(ii,1);
idx = sub2ind([x,y,z],ij{:});
A = s(idx);
B = s(setdiff(1:numel(s),idx));
  1 件のコメント
muhammad ismat
muhammad ismat 2015 年 6 月 10 日
Thank you very much Mr. Andrei Bobrov

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

その他の回答 (2 件)

Guillaume
Guillaume 2015 年 6 月 9 日
I'll assume you know how to read the text file (use load). One way to do it:
coordinates = [1 2 1
3 1 1
2 3 1];
s = [0.3 0.4 0.6
0.1 0.5 0.7
0.2 0.11 0.9];
linindices = sub2ind(size(s), coordinates(:, 1), coordinates(:, 2))';
A = s(linindices)
B = s(setdiff(1:numel(s), linindices))
  1 件のコメント
muhammad ismat
muhammad ismat 2015 年 6 月 10 日
Thank you very much Mr. Guillaume

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


Walter Roberson
Walter Roberson 2015 年 6 月 9 日
dlmread() or load() the text file into a matrix, and then work with it in memory.
  1 件のコメント
muhammad ismat
muhammad ismat 2015 年 6 月 10 日
Thank you , Mr Walter

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

カテゴリ

Help Center および File ExchangeLive Scripts and Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by