Hello!
I am a newby to Matlab, and I have a small code fragment I cannot understand.
I need to know what the following lines do, but even trying to visualize them in Matlab, I was not able to find out the meaning:
p(:, :, 1)=u(:, [2:width, width])
p(:, :, 2)=u([2:height, height], :)
p(:, :, 1)=p(:, :, 1)
Can you please explain what those the above lines mean?
Thank you.

Réponses (1)

Star Strider
Star Strider le 24 Oct 2022
It is likely easiest to assign a value to ‘height’ and ‘width’ and see the result —
height = 4; % Create VAlue
width = 5; % Create Value
u = randi(9,height,width) % Create Matrix
u = 4×5
6 7 1 8 2 8 3 1 9 1 4 2 3 1 6 1 8 4 5 8
p(:, :, 1)=u(:, [2:width, width])
p = 4×5
7 1 8 2 2 3 1 9 1 1 2 3 1 6 6 8 4 5 8 8
p(:, :, 2)=u([2:height, height], :)
p =
p(:,:,1) = 7 1 8 2 2 3 1 9 1 1 2 3 1 6 6 8 4 5 8 8 p(:,:,2) = 8 3 1 9 1 4 2 3 1 6 1 8 4 5 8 1 8 4 5 8
p(:, :, 1)=p(:, :, 1) % This Is Obviously Redundant, Since It Assigns The First Page To The First PAge
p =
p(:,:,1) = 7 1 8 2 2 3 1 9 1 1 2 3 1 6 6 8 4 5 8 8 p(:,:,2) = 8 3 1 9 1 4 2 3 1 6 1 8 4 5 8 1 8 4 5 8
.

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by