Scale 3D matrix by 10i

조회 수: 5 (최근 30일)
Johnny
Johnny 2014년 1월 26일
답변: Andrei Bobrov 2014년 1월 26일
M = randi([5 10], 1);
N = randi([5 10], 1);
P = randi([20 30], 1);
Y = round(-10 + (10 - (-10)).*rand(M, N, P));
===================================
indexes = 1:P;
scaling = repmat(indexes(:), [M, N, P])
Yscaled = Y.*(scaling.*10)
How I understand this question is that I have to create another 3D matrix and multiple the two (matrix) in order to scale it
How to I create a 3D matric: first page all 1 , second page all 2 , etc up to P

답변 (3개)

Image Analyst
Image Analyst 2014년 1월 26일
편집: Image Analyst 2014년 1월 26일
Hint:
y=cat(3, ones(2), 2*ones(2), 3*ones(2)) % Sample initial data.
[rows, columns, planes] = size(y)
m = 10*(1:planes)
m2 = imresize(m', [numel(y), 1], 'nearest')
y_out = reshape(.......
Finish the last line by yourself and it will be done. imresize() requires the Image Processing Toolbox. Type ver to see if you have it.

Johnny
Johnny 2014년 1월 26일
편집: Johnny 2014년 1월 26일
% Create a indexes vector
indexes = 1:P;
% Make indexes array into individual pages
n = reshape(indexes,1,1,P)
% Create a 3-dimensional matrix from indexes vector
m = repmat(n,M,N)
% Elementwise multiplication between matrix m and Y
Yscaled = Y.*(m.*10)
  댓글 수: 1
Amit
Amit 2014년 1월 26일
Very nice. You're getting a hang of MATLAB.

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


Andrei Bobrov
Andrei Bobrov 2014년 1월 26일
Yscaled = bsxfun(@times,Y,reshape(1:P,1,1,[])*10)

카테고리

Help CenterFile Exchange에서 Holidays / Seasons에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by