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.

1 次查看(过去 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