can someone check my code?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello!
I have a problem in my code, can anyone help me please?
i have a matrix A(1826*3600) randomly generated contains such values.
i will fill another matrix B based on elements of A, but not all elements(such specific columns)
the first step i did is to generate a vector contains number of specific columns i want to fill.
this is my case :
i created a vector from 1 to 720 element(number of specific columns i want to fill).
S=linspace(1,720,720)
i will check the value in matrix A (in this case for value =50), then i will fill P with my formula.
for i=1:1826
for j=1:3600
for k=1:720
if A(i,j)==50
P(i,j)=(50*S(k))/3600;
else P(i,j)=0;
end
end
end
end
this code doesn't work, also i need to elements can't exceed the bounds of my matrix.
i will be grateful if you could help me!
Please HELP!!!!
5 comentarios
Walter Roberson
el 1 de Oct. de 2022
for k=1:720
if A(i,j)==50
Does A(i, j) change inside the for k loop? The next k value, would you not be testing the same A(i, j)? So the end result is going to be the same as it would be if you only did for k=720 and no other iterations.
Respuestas (1)
Sulaymon Eshkabilov
el 1 de Oct. de 2022
Here is the corrected code:
A=randi([0, 111], 1826, 3600);
S=1:720;
P= zeros(1826, 3600);
for i=1:1826
for j=1:3600
for k=1:720
if A(i,j)==50
P(i,j)=(50*S(k))/3600;
end
end
end
end
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!