Effacer les filtres
Effacer les filtres

Is it a loop problem ?

2 vues (au cours des 30 derniers jours)
Netanel malihi
Netanel malihi le 21 Juil 2020
Commenté : Netanel malihi le 23 Juil 2020
Hello, this program needs to count the number of colors every 15 minutes for 6 hours (0:24 iteration).at the end of each iteration a graph is shown with all the colors and, at the end of the loop one more graph shows the amount of each color and the max and min. the problem I encountered is that the program asks the dimension of the matrix each time and shows the max/min graphs after each one but, I would like the program to ask for the dimension only one time and to show the max/min and amount per time frame only at the end of the loop for all colors.
the script is in the .xlsx file.
helping solve the issue will be much appreciated, guys.
  2 commentaires
waqas
waqas le 21 Juil 2020
Goood idea would be to just paste the code as .m file so that it can be easily implemented. Right now it is not very clear.
Netanel malihi
Netanel malihi le 21 Juil 2020
ok,i added one .

Connectez-vous pour commenter.

Réponse acceptée

waqas
waqas le 21 Juil 2020
The program can be stopped by using input to
MatrixDimInput(iteration)
%Modification in the function would result
function [m,n]=MatrixDimInput(iter)
errorFlag=0 %errorFlag=0 if there is no error in the input. errorFlag=1 if an error is found.
while 1
if errorFlag==0 && iter ==0 %if there is no error
prompt='Enter the matrix dimensions m x n. \n m is between 4 to 10, n is between 7 to 12. \n Enter m (4 to 10): '
prompt2='Enter n (7 to 12): '
m=input(prompt)
n=input(prompt2)
end
if (m>=4 && m<=10 && n>=7 && n<=12 && rem(m,1)==0 && rem(n,1)==0)
errorFlag=0 %no errors found
break
else
errorFlag=1 %Error is found
error='The dimensions you entered are incorrect. \n Please make sure that m is between 4 to 10, and n is between 7 to 12. \n Enter m (4 to 10): '
error2='Enter n (7 to 12): '
m=input(error)
n=input(error2)
end
end
end
Problem with this is that it will not have m and n in the next iterations: so better idea would be to take out m and n inputs out of the function and give them as inputs (Implementation in attached in the .m file). However, the value of m and n would remain the same for every iteration after the first values that you select.
if iteration == 0
prompt='Enter the matrix dimensions m x n. \n m is between 4 to 10, n is between 7 to 12. \n Enter m (4 to 10): '
prompt2='Enter n (7 to 12): '
m_initial=input(prompt)
n_initial=input(prompt2)
end
[m,n]=MatrixDimInput(m_initial,n_initial)
function [m,n]=MatrixDimInput(m_in,n_in)
errorFlag=0 %errorFlag=0 if there is no error in the input. errorFlag=1 if an error is found.
while 1
if (m_in>=4 && m_in<=10 && n_in>=7 && n_in<=12 && rem(m_in,1)==0 && rem(n_in,1)==0)
errorFlag=0 %no errors found
m = m_in;
n = n_in;
break
else
errorFlag=1 %Error is found
error='The dimensions you entered are incorrect. \n Please make sure that m is between 4 to 10, and n is between 7 to 12. \n Enter m (4 to 10): '
error2='Enter n (7 to 12): '
m=input(error)
n=input(error2)
end
end
end
  1 commentaire
Netanel malihi
Netanel malihi le 22 Juil 2020
Thank you now it works well, except for one thing. If I enter wrong dimensions the first time and afterward correct dimensions it keeps giving error message 'wrong dimensions please try again....'

Connectez-vous pour commenter.

Plus de réponses (1)

Netanel malihi
Netanel malihi le 22 Juil 2020
anyone know how to fix it ?
when I enter wrong dimensions the first time and afterward correct dimensions it keeps giving error message 'wrong dimensions please try again....'
  4 commentaires
Netanel malihi
Netanel malihi le 22 Juil 2020
correct, I would like to assign the dimensions only once, but when I gave the wrong dimensions the program asked to put the correct one I did and it gave the same error.
now, I changed the lines and it solved the first problem but, now after the first sample, the loop stops, and I am asked to put the dimensions again.
thanks for your help it's greatly appreciated.
Netanel malihi
Netanel malihi le 23 Juil 2020
even if i assign correct dimensions error is given.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by