hi,
how do i replace all the members of an array with with anoda set of arrays.. for example
a = [ q1 q2 q3 q4]
b = [1 2 3 4 2 4 3 1 2 1 3 4 3 2 1 2 3 4 1 3 2 4]
how do i replace the members of a with where q1=1, q2=2, q3=3 and q4=4 pls i will appreciate any help i can get for this.
thanks in advance

4 件のコメント

Sven
Sven 2011 年 11 月 15 日
Select the code in your post and hit the "code" button to make it easier to read.
One problem we will all have is that your first statement:
a = [ q1 q2 q3 q4]
is not valid MATLAB code, so I don't quite understand what you're trying to do... can you clarify?
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 15 日
What does b have anything to do with this?
deji
deji 2011 年 11 月 15 日
the elements in a are to replace the elements in b
Dr. Seis
Dr. Seis 2011 年 11 月 15 日
Ah, then use my last suggestion if you are using the elements in b for indexing.

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

 採用された回答

Dr. Seis
Dr. Seis 2011 年 11 月 15 日

0 投票

Are you trying to create a row vector with all the different combinations of q1, q2, q3, and q4?
If so:
q1=11; q2=22; q3=33; q4=44;
a = [q1 q2 q3 q4];
b = reshape(a(perms(1:length(a)))',[1,numel(perms(1:length(a)))]);
If you would rather have a matrix of the different combinations, then:
b = a(perms(1:length(a)));
Or, if the order of b is really as you describe above, then use b as indices to a:
b = [1 2 3 4 2 4 3 1 2 1 3 4 3 2 1 2 3 4 1 3 2 4];
c = a(b);

2 件のコメント

bym
bym 2011 年 11 月 15 日
yes but the OP said q1 =1...etc, in which case
a(b) == b
I don't get the question
Dr. Seis
Dr. Seis 2011 年 11 月 15 日
Yeah, I changed it just to demonstrate that the elements in a do not necessarily need to be 1:4, but the indexing needs to be 1:length(a) in order to do any rearranging they may want to do. I, too, do not understand fully... just a few guesses.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2011 年 11 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by