While loop does not repeat
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
clc;close all;clear all;
[~,Spot]= xlsread('parkingspot.xlsx','A1:B4');
pick =choose();
spotcheck = strcmpi(Spot,'V');
spotcheck = 1;
while (spotcheck == 1)
spotcheck = {spotcheck};
pick =choose();
end
xlswrite('parkingspot.xlsx','V',1,pick);
The excel file that i load in:
Spot =
2×2 cell array
{'V'} {'V' }
{'V'} {0×0 char}
The pick =choose() function:
list = {'A1','A2','A3','A4','B1','B2','B3','B4'};
[pick,tf] = listdlg('PromptString',{'Select a Parking Spot.',...
'Checking if slot still available.',''},...
'SelectionMode','single','ListString',list);
switch pick
case 1
pick = 'A1';
case 2
pick = 'A2';
case 3
pick = 'A3';
case 4
pick = 'A4';
case 5
pick = 'B1';
case 6
pick = 'B2';
case 7
pick = 'B3';
case 8
pick = 'B4';
So the idea is if i pick "B4" it will check if B4 has a 'V' value in the cell, and if not it will repeat the choosing step, but the while() loop doesnt seem to work, please help
0 comentarios
Respuestas (1)
Cris LaPierre
el 16 de Mayo de 2021
Editada: Cris LaPierre
el 16 de Mayo de 2021
Be careful. You are heading down the path of creating an infinite loop.
Your loop is not running multiple times right now due to the syntax error you are getting (the red error message).
spotcheck = 1;
% This line represents how you set spotcheck in your while loop
spotcheck = {spotcheck}
% This line represents the comparison performed in your while loop conditional statement
spotcheck == 1
Perhaps you have removed some of your code in an attempt to simplify your example? The way to fix the error in what you have shared is to not use the curly braces when assigning a value to spotcheck.
2 comentarios
Cris LaPierre
el 17 de Mayo de 2021
If you do not remove them, you will continue to have this error.
Ver también
Categorías
Más información sobre Downloads 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!