i have an array like A= [ 51 22 33 56 67 78 .....] and i have one more matrix of size[1000 300] i need to remove A[] values in matrix.

조회 수: 2 (최근 30일)
i.e in first coloum of matrix i need to remove first 51 and last 51 values in second coloum i need to remove first 22 and last 22 values in third coloum i need remove first 33 and last 33 values....

채택된 답변

Akira Agata
Akira Agata 2017년 11월 29일
I think one possible solution would be like this.
A = [51 22 33 56];
B = rand(1000, 4);
% Remove first A(kk) and last A(kk) elements from kk-th column of B (for kk = 1 to 4)
for kk = 1:numel(A)
B([1:A(kk), end-A(kk)+1:end],kk) = NaN;
end

추가 답변 (1개)

M
M 2017년 11월 29일
you can use something like
M=magic(5);
A=[1 2 1 0 3];
res=cell(length(A),1);
for i=1:length(A)
res{i}=M(A(i)+1:end-A(i),i);
end
which gives
M =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
res =
5×1 cell array
{3×1 double}
{[ 6]}
{3×1 double}
{5×1 double}
{0×1 double}

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by