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 visualización (últimos 30 días)
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....

Respuesta aceptada

Akira Agata
Akira Agata el 29 de Nov. de 2017
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

Más respuestas (1)

M
M el 29 de Nov. de 2017
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}

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by