I have a matrix and a vector, I want to repmat them the same my mean is that if I change the first row of the matrix I want this also happen the same for the vector,

댓글 수: 2

Oleg Komarov
Oleg Komarov 2011년 9월 7일
Your request doesn't make sense without additional information. What's your goal? How the change happens?
Niki
Niki 2011년 9월 7일
X=rand(4) and Y=rand(4,1)
for example
X=[ 0.1734 0.0605 0.6569 0.0155
0.3909 0.3993 0.6280 0.9841
0.8314 0.5269 0.2920 0.1672
0.8034 0.4168 0.4317 0.1062]
and
Y =
0.3724
0.1981
0.4897
0.3395
Then I want randomly change the X rows simultaneously with Y
for example next one X become
X=[ 0.3909 0.3993 0.6280 0.9841
0.8314 0.5269 0.2920 0.1672
0.8034 0.4168 0.4317 0.1062
0.1734 0.0605 0.6569 0.0155
]
(the first row went to the last row )
for Y also the same
Y=[0.1981
0.4897
0.3395
0.3724
]

댓글을 달려면 로그인하십시오.

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 9월 7일

1 개 추천

X=rand(4)
Y=rand(4,1)
Index=[2 3 4 1];
X=X(Index,:)
Y=Y(Index,:)

댓글 수: 5

Niki
Niki 2011년 9월 7일
Thanks, but I would like to perform it automatically and not doing it manually, I would like to perform it randomly and not based on my knowledge
Fangjun Jiang
Fangjun Jiang 2011년 9월 7일
What do you mean? I thought your question is about the synchronization of changes made on two matrix, which the code does. If you want to do it randomly, then come up with a random way to generate the Index. You have to specify the Index, do you? Maybe Index=randperm(4)?
Niki
Niki 2011년 9월 7일
Yes, It works
just we should use of
Index=randperm(4)';
Niki
Niki 2011년 9월 7일
Thanks Fangiun, you are always ready for my questions and at least you read my questions and try to answer , Thanks
I gave you a vote just for your kindness
Fangjun Jiang
Fangjun Jiang 2011년 9월 7일
You are welcome! BTW, Index=randperm(4);X=X(Index,:); works too!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Honglei Chen
Honglei Chen 2011년 9월 7일

0 개 추천

An alternative approach is to use left-multiply to achieve row manipulation. In your case, if you want to move your first row to the last, the corresponding matrix is
T = [0 1 0 0;0 0 1 0;0 0 0 1;1 0 0 0]
Then you can do
X = T*X
Y = T*Y
As long as you can build T, then you can the manipulate them together.
HTH
Walter Roberson
Walter Roberson 2011년 9월 7일

0 개 추천

What you are asking to do is not possible with ordinary numeric datatypes.
You could create a new object-oriented data class that did the work for you.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2011년 9월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by