specifying an array size

20 visualizaciones (últimos 30 días)
charles
charles el 8 de Mzo. de 2023
Respondida: Chunru el 8 de Mzo. de 2023
clear
count=1
A =randi([1,9999],10,31)
[row,col]=size(A)
for i=1: row
for j =1:col
%%to check if this number appears and then store than index in another
%%array
if A(i,j)==4000
b=[i,j]
count = count+1;
%% I would like to have the count as the amount of rows, and two columns for i and j
b=[,count;,;]
end
end
end

Respuesta aceptada

Chunru
Chunru el 8 de Mzo. de 2023
count=0;
b = [];
%A =randi([1,9999],10,31);
A =randi([1,60],10,31);
[row,col]=size(A);
for i=1: row
for j =1:col
%if A(i,j)==4000
if A(i,j)==10
count = count+1;
b=[b; count i,j];
end
end
end
b
b = 7×3
1 3 4 2 5 21 3 5 27 4 6 2 5 7 25 6 9 6 7 9 14

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations 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