How can I transfer specific values to a new variable?

1 次查看(过去 30 天)
Hello,
I got a matrix full of values:
z= rand(10,4)
z =
0.9058 0.9706 0.0357 0.0318
0.1270 0.9572 0.8491 0.2769
0.9134 0.4854 0.9340 0.0462
0.6324 0.8003 0.6787 0.0971
0.0975 0.1419 0.7577 0.8235
0.2785 0.4218 0.7431 0.6948
0.5469 0.9157 0.3922 0.3171
0.9575 0.7922 0.6555 0.9502
0.9649 0.9595 0.1712 0.0344
0.1576 0.6557 0.7060 0.4387
I got another matrix with the properties of every value (in reality it's the same size as the matrix z)
y =[1 2 3 4; 3 2 1 4; 4 3 2 1]
y =
1 2 3 4
3 2 1 4
4 3 2 1
Then I would like to transfer every z value with the corresponding y value =1 into another 10x1 matrix.
Select everything with a y=1
0.9058
0.8491
0.0462
How can I do this?

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2019-7-9
z(y==1)?

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by