Assignment has more non-singleton rhs dimensions than non-singleton subscripts?
Mostrar comentarios más antiguos
Hello, here is my code:
for f = 1:n ind(f,1) = num2cell(find(edges{f,1} == inde_x),2); in_d(f,1) = size(ind{f,:},2); indx = find(in_d ~= 0); end
I have edges matrix 9x1 cell and inde_x = 6
See the edges matrix below [6 9] [1 5] [5 6] [6 9] [6 7] [1 5] [5 9] 7 [1 7]
I'am trying to find values in inde_x = 6 in the edges matrix and ind matrix is formed as follows:
1 [] 2 1 1 [] [] 1 []
As seen above, in the edges matrix is equal to 6 in the row 6 finds the number and writes number of the index. If there is no value equal to 6, the [] sign is written but the number {8,1} does not have a value of 6, but the number 1 occurs and the following error is written:
Error in aaaaaaaaaaaaa (line 125) ind(f,1) = num2cell(find(edges{f,1} == inde_x),2);
How can I solve this problem? Thanks.
3 comentarios
Jan
el 22 de Oct. de 2018
The question is not clear. Start with formatting the code using the "{} Code" button, see How to format code in the forum.
The names of the variables ind, inde_x, in_d, indx are really confusing. I recommend to use smarter names.
The show "edge matrix" is not clear. Please use the standard Matlab syntax to define a matrix.
"1 [] 2 1 1 [] [] 1 []" This does not form a matrix. Matrix elements cannot be empty.
"As seen above, in the edges matrix is equal to 6 in the row 6 finds the number and writes number of the index" - I do not understand this sentence. I do not see this above.
"the [] sign is written but the number {8,1}" - this is not clear also. [] is the concatenation operator, not a "sign".
" and the following error is written: ..." - This is only the part of the error message, which tells, where the error occurs. The other parts matter also, which explain what the error is.
Abdullah Türk
el 22 de Oct. de 2018
Guillaume
el 22 de Oct. de 2018
I was going to ask why you'd use a cell array instead of a Nx2 matrix to store edges then saw that one of your edge has only one element. Why? Don't your edge describe a graph? If so all edges should have two elements. If it's a self-loop, the node should be repeated.
Respuesta aceptada
Más respuestas (1)
KSSV
el 22 de Oct. de 2018
k = 6;
n = 9;
edges{1,1} = [6 9]
edges{2,1} = [1 5]
edges{3,1} = [5 6]
edges{4,1} = [6 9]
edges{5,1} = [6 7]
edges{6,1} = [1 5]
edges{7,1} = [5 9]
edges{8,1} = 7
edges{9,1} = [1 7]
A = cell(n,1) ;
for f = 1:n
T = num2cell(find(edges{f,1} == k),2) ;
if ~isempty(T)
A(f,1) = T;
else
A(f,1) = {[]};
end
end
1 comentario
Abdullah Türk
el 22 de Oct. de 2018
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!