Zero Matrix Values using Indices
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Voss
2022년 9월 17일
편집: Voss
2022년 9월 17일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!