フィルターのクリア

HOW TO SELECT ELEMENTS FROM DIFFERENT MATRIX

1 回表示 (過去 30 日間)
PRANAY DISHAN
PRANAY DISHAN 2018 年 2 月 8 日
コメント済み: PRANAY DISHAN 2018 年 2 月 8 日
Hello every one an trying to select elements from three different matrices which is stored in a template but the output is not correct. Following is my requirment.
harmony.Sol %template consisting of three 1x6 matrices as shown below:
[1 2 3 4 5 6]
[7 8 9 1 2 3]
[ 4 5 6 7 8 9]
i need to select random elements from above three matrices and create a new 1x6 matrix. probably named harmony.new. Ex: ans= [7 5 3 1 5 9]
Please help me on this, my codes are not giving the correct output. Thank u...
  3 件のコメント
PRANAY DISHAN
PRANAY DISHAN 2018 年 2 月 8 日
yes sir,
harmony(1).Sol gives [1 2 3 4 5 6]
harmony(2).Sol gives [7 8 9 1 2 3]
harmony(3).Sol gives [ 4 5 6 7 8 9]
and i have to create new 1x6 matrix from them probably named harmony.new. Ex: ans= [7 5 3 1 5 9] (which is randomly chosen from harmony.Sol)
Walter Roberson
Walter Roberson 2018 年 2 月 8 日
If harmony is a non-scalar structure, then which entry in harmony should get the new value? It is not possible to have a structure which is non-scalar with respect to some fields but scalar with respect to other fields.

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 2 月 8 日
val = vertcat(harmony.Sol);
nchoice = size(val,1);
ncol = size(val,2);
ridx = randi(nchoice, 1, ncol);
harmony(173).new = val((0:ncol-1)*nchoice + ridx);
  1 件のコメント
PRANAY DISHAN
PRANAY DISHAN 2018 年 2 月 8 日
Thank you sir. It was very helpful.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by