Zero Matrix Values using Indices
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ben Whitby
el 16 de Sept. de 2022
Comentada: Voss
el 17 de Sept. de 2022
Hi All,
I have two matrices. The first is an 8x6 matrix (Speed_ENU) that contains some measured data. The second matrix (HubHeight) contains integers corresponding to particular rows in the first matrix. I want to set the values corresponding the indices in ind to zero. I have the follwing code so far. The comments in the code explain what I am trying to do.
This is as far as I get. How can I set the values in Speed_ENU corresponding to the Indexes in ind to zero???????
clc
clear all
Speed_ENU = [1,3,6,14,25,33; 11,12,15,45,15,67;1,32,16,4,25,3; 11,12,5,45,15,7;11,32,6,4,25,33; 1,12,5,44,15,67;11,31,6,4,25,3; 1,22,5,5,9,7 ]
HubHeight = [6,6,6,4,5,5]
[sz1,sz2]=size(Speed_ENU);
row = HubHeight; %We want to set all the values at Hub Height to zero
col = [1:sz2];
sz = size(Speed_ENU)
ind = sub2ind(sz,row,col) %Returns the linear Indices corresponding to the row and column subscripts in Speed_ENU
Speed = (Speed_ENU(ind)); %This is as far as I get. How can I set the values in Speed_ENU corresponding to
% the Indexes in ind to zero???????
0 comentarios
Respuesta aceptada
Voss
el 17 de Sept. de 2022
Editada: Voss
el 17 de Sept. de 2022
Speed_ENU = [1,3,6,14,25,33; 11,12,15,45,15,67;1,32,16,4,25,3; 11,12,5,45,15,7;11,32,6,4,25,33; 1,12,5,44,15,67;11,31,6,4,25,3; 1,22,5,5,9,7]
HubHeight = [6,6,6,4,5,5];
[sz1,sz2] = size(Speed_ENU);
% row = HubHeight;
% col = 1:sz2;
% sz = size(Speed_ENU);
% ind = sub2ind(sz,row,col);
% no need for the variables row, col, sz:
% (no need for ind either, really)
ind = sub2ind([sz1 sz2],HubHeight,1:sz2)
Speed_ENU(ind) = 0
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!