wat is function of scale and size?

1 visualizzazione (ultimi 30 giorni)
Madhava Teja Munagala
Madhava Teja Munagala il 14 Mar 2018
if size(i,3)>1
i=rgb2gray(i);
wat is size(i,3),here i is image and 3 is what
scale=2; if scale>0 here scale gives what

Risposte (1)

Pawel Jastrzebski
Pawel Jastrzebski il 14 Mar 2018
Modificato: Pawel Jastrzebski il 14 Mar 2018
size (x,3) calculates the depth of a 3D array.
Function size calculate the dimensions of the array. The additional parameter (1,2,3) tells which size specifically should be calculated.
Consider the examples below and also read on size doc:
% dimensions
x = 5
y = 6
z = 7
% 2D matrix of random values
m2D = rand(x,y)
% 3D matrix of random values
m3D = rand(x,y,z)
% using 'size' on a 2D matrix:
s2D = size(m2D) % gives 'x' and 'y' dimensions
s2Dx = size(m2D,1) % gives 'x' dimension only
s2Dy = size(m2D,2) % gives 'y' dimension only
s2Dz = size(m2D,3) % gives 1, as there's no depth
% using 'size' on a 3D matrix:
s3D = size(m3D) % gives 'x', 'y' and 'z' dimensions
s3Dx = size(m3D,1) % gives 'x' dimension only
s3Dy = size(m3D,2) % gives 'y' dimension only
s3Dz = size(m3D,3) % gives 'z' dimension only
  2 Commenti
Madhava Teja Munagala
Madhava Teja Munagala il 14 Mar 2018
Thank u, wat is the output of these code
Pawel Jastrzebski
Pawel Jastrzebski il 14 Mar 2018
Modificato: Pawel Jastrzebski il 14 Mar 2018
I don't want to be rude, but can't you run the code yourself to find out the output?
The output is explained in the comments.
>> % dimensions
x = 5
y = 6
z = 7
% 2D matrix of random values
m2D = rand(x,y)
% 3D matrix of random values
m3D = rand(x,y,z)
% using 'size' on a 2D matrix:
s2D = size(m2D) % gives 'x' and 'y' dimensions
s2Dx = size(m2D,1) % gives 'x' dimension only
s2Dy = size(m2D,2) % gives 'y' dimension only
s2Dz = size(m2D,3) % gives 1, as there's no depth
% using 'size' on a 3D matrix:
s3D = size(m3D) % gives 'x', 'y' and 'z' dimensions
s3Dx = size(m3D,1) % gives 'x' dimension only
s3Dy = size(m3D,2) % gives 'y' dimension only
s3Dz = size(m3D,3) % gives 'z' dimension only
x =
5
y =
6
z =
7
m2D =
0.1599 0.9759 0.8343 0.9044 0.5714 0.3581
0.6668 0.0309 0.8136 0.6804 0.9817 0.9869
0.0179 0.4939 0.6290 0.3788 0.8497 0.0840
0.1197 0.8627 0.0022 0.6320 0.2834 0.2503
0.9521 0.2429 0.3797 0.2433 0.6825 0.8113
m3D(:,:,1) =
0.0844 0.4379 0.9053 0.7831 0.2488 0.9258
0.5313 0.3504 0.6402 0.6857 0.3193 0.1788
0.8006 0.4785 0.1629 0.4662 0.9108 0.5175
0.7388 0.5874 0.5659 0.2603 0.8852 0.6270
0.1417 0.1458 0.9316 0.5693 0.7946 0.9132
m3D(:,:,2) =
0.6640 0.0850 0.3801 0.3781 0.6853 0.2602
0.3892 0.9224 0.8128 0.2489 0.6203 0.8775
0.7400 0.0536 0.2441 0.2529 0.7467 0.8061
0.8176 0.5270 0.8844 0.7672 0.9773 0.4611
0.6003 0.1189 0.7126 0.0499 0.3839 0.0910
m3D(:,:,3) =
0.5643 0.7267 0.0525 0.9084 0.8506 0.5173
0.1874 0.5158 0.8012 0.5100 0.1445 0.9905
0.5317 0.7906 0.6786 0.6149 0.3705 0.2265
0.3550 0.2045 0.9460 0.3161 0.6224 0.3980
0.3148 0.6781 0.0916 0.0775 0.9976 0.6966
m3D(:,:,4) =
0.0646 0.3191 0.7346 0.4968 0.4658 0.2886
0.7477 0.9861 0.6373 0.0224 0.5609 0.2690
0.4204 0.7182 0.0738 0.0538 0.4945 0.5942
0.8113 0.4132 0.1205 0.1409 0.0678 0.4759
0.3796 0.0986 0.9816 0.8935 0.8976 0.3683
m3D(:,:,5) =
0.6556 0.4391 0.5199 0.5669 0.0478 0.9374
0.9382 0.0273 0.0538 0.6804 0.7383 0.5134
0.6204 0.8762 0.8622 0.3714 0.0380 0.2409
0.2828 0.6101 0.4429 0.0782 0.9542 0.2600
0.2052 0.2036 0.5480 0.4564 0.7424 0.7590
m3D(:,:,6) =
0.9933 0.4306 0.6401 0.3081 0.7598 0.4369
0.3567 0.7307 0.1320 0.4024 0.2909 0.3043
0.7529 0.2612 0.4528 0.8842 0.2774 0.2909
0.1100 0.0948 0.6522 0.7006 0.0061 0.2425
0.5970 0.4510 0.8270 0.2419 0.3747 0.9367
m3D(:,:,7) =
0.8602 0.2698 0.3320 0.5433 0.4825 0.1319
0.3972 0.9897 0.7487 0.2514 0.4427 0.3559
0.4794 0.1837 0.6444 0.5786 0.3118 0.3959
0.5650 0.8617 0.1692 0.9155 0.0553 0.8855
0.4896 0.0326 0.9522 0.8956 0.7538 0.0212
s2D =
5 6
s2Dx =
5
s2Dy =
6
s2Dz =
1
s3D =
5 6 7
s3Dx =
5
s3Dy =
6
s3Dz =
7
>>

Accedi per commentare.

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by