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 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
parameshwarisimmalu
il 29 Nov 2017
Commentato: parameshwarisimmalu
il 29 Nov 2017
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....
0 Commenti
Risposta accettata
Akira Agata
il 29 Nov 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
Più risposte (1)
M
il 29 Nov 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}
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!