Replace a value with matrix n x m
古いコメントを表示
Hii.... I want to ask how to replace a value with a matrix n x m. Ex: a = (perms[2])', if a(1)=1, replace a(1)with [1 1;1 1], if a(1)=2, replace it with [2 2;2 2].
Thank you
Muammar
採用された回答
その他の回答 (2 件)
Sean de Wolski
2011 年 12 月 5 日
Maybe:
data1 = ones(2);
data2 = magic(2);
D = [data1;data2];
D2 = reshape(flipdim(reshape(D',size(data1,1),size(data1,2),[]),3),size(D))
?
9 件のコメント
Muammar
2011 年 12 月 5 日
Walter Roberson
2011 年 12 月 5 日
Sorry, I do not understand what you are trying to say here. The part that I do understand has no obvious connection to replacing the 1x1 entry at A(1) with the 2x2 entry [1,1;1,1] or [2,2;2,2] that you were asking about ?
Sean de Wolski
2011 年 12 月 5 日
Walter, I think he wants the result to be the switch the concatention order of data1,data2, though it's very unclear.
Muammar
2011 年 12 月 5 日
Muammar
2011 年 12 月 5 日
Image Analyst
2011 年 12 月 5 日
Huh? You didn't change A at all. It's still [data1;data2] which is [1 1;4 4] - no change at all. And what is supposed to be a 1x1 matrix?
Walter Roberson
2011 年 12 月 5 日
A=[1 1;4 4] is not a 1 x 1 matrix: it is a 2 x 2 matrix. The only way to make a 1 x 1 matrix as a result would be to use
A = {[1 1;4 4]};
which would create a 1 x 1 cell array.
Muammar
2011 年 12 月 5 日
Muammar
2011 年 12 月 5 日
Image Analyst
2011 年 12 月 5 日
I agree with the others - unclear. Perhaps you mean this:
m = randi(9, [1 4]) % Sample row vector with random integers
m2 = imresize(m, 2, 'nearest') % Do the replication.
Results:
m =
7 8 2 5
m2 =
7 7 8 8 2 2 5 5
7 7 8 8 2 2 5 5
So maybe you can just simply use imresize to get what you want.
カテゴリ
ヘルプ センター および File Exchange で Descriptive Statistics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!