concatenate a vector in column-major order

I am trying to solve a problem where the elements of a vector is compared to something and if found true the location of the element (say(1,2)) is output into another vector in a column-major order . my problem is that the vector returns the location of the last element, it overrides the elements before it instead of concatenating it. e,g if the locations of the elements are (1,2) (3,2) (4,1). it returns only (4,1). how do I make it to concatenate and how do I set it to column-major order?

1 comentario

Azzi Abdelmalek
Azzi Abdelmalek el 2 de Jun. de 2016
Your question is not clear, post your code, you can also, illustrate with an example

Respuestas (2)

OLUBUKOLA ogunsola
OLUBUKOLA ogunsola el 2 de Jun. de 2016

0 votos

indexes=[]; for ii= 1:size (X,1); for jj = 1: size (X , 2); if X(ii , jj)< ii*jj; indexes = {ii ,jj}; end end end
Jos (10584)
Jos (10584) el 2 de Jun. de 2016
X = randi(20,6,4)
[ii,jj] = ndgrid(1:size(X,1), 1:size(X,2))
tf = X < ii.*jj
ii(tf)
jj(tf)

5 comentarios

sorry i don't really understand what is going on here ,but the code failed for X = [0;1;2;3;4;5;6;7;8;9;10]. this is what i got
ans =
1
2
3
4
5
6
7
8
9
10
11
ans =
1
1
1
1
1
1
1
1
1
1
1
Jos (10584)
Jos (10584) el 3 de Jun. de 2016
What did you expect? This code produces the rows ii and columns jj were X(ii,jj) < ii*jj ...
OLUBUKOLA ogunsola
OLUBUKOLA ogunsola el 4 de Jun. de 2016
this is what i came up with with your suggestions : function indexes = small_elements ( X) indexes=[]; for ii= 1:size (X,1); for jj = 1: size (X , 2); if X(ii , jj)< ii*jj; a=[ii jj]; indexes=[indexes; a]; end end end it passed for several inputs except [0;1;2;3;4;5;6;7;8;9;10] I'm sure sure it has to do with the column major order which is a condition required from the question of the output
im pasting the code again because it was jumbled together
function indexes = small_elements ( X)
indexes=[];
for ii= 1:size (X,1);
for jj = 1: size (X , 2);
if X(ii , jj)< ii*jj;
a=[ii jj];
indexes=[indexes; a];
end
end
end
Jos (10584)
Jos (10584) el 4 de Jun. de 2016
Without an input, how can we know your code is incorrect?

La pregunta está cerrada.

Preguntada:

el 2 de Jun. de 2016

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by