xlswrite not working within while loop

4 views (last 30 days)
dweather
dweather on 8 Mar 2019
Commented: dweather on 8 Mar 2019
Hi all
I was hoping for some help, I'm trying to write a while loop which allows users to repeatedly enter some parameters which are then written to an excel sheet and then used by another function to perform a task.The intention is the user analyses the output of the main function and then uses this loop to refine the parameters and re-run the main function repeatedly until they are happy with the result:
while (choice2 == 2) && (choice3 == 1)
prompt = {'Diameter of largest sticker (in pixels)', 'Diameter of smallest sticker (in pixels'}; % asks the user to specify the max and min axis which will be the bounding values for sticker identification - useful as a tuneable to avoid messing around with the input image
title = 'Specify the largest and smallest stickers for identification';
dims = [1 45];
definput = {'45','10'};
stickersdims = inputdlg(prompt,title,dims,definput);
maxaxis = (stickersdims{1});
minaxis = (stickersdims{2});
UVNclearstr = {'';'';'';'';'';'';'';''};
UVNstr = {refstr; stickers; refstr; VEHICLE2; 50; 'freestream.jpg'; maxaxis; minaxis}; % sets the parameters to be written to the excel sheet including folder locations, file name and max/min axis
xlswrite('UVN_data.xlsx',UVNclearstr,'UV Labels Run1',UVNrange); % clears cells within the excel sheet ready for population of parameters
xlswrite('UVN_data.xlsx',UVNstr,'UV Labels Run1',UVNrange); % writes parameters to the excel
cd (currentFolder);
UVN_v5_1;
choice2 = menu('Has the normalisation image been created correctly', 'Yes','No');
if choice2 == 2
choice3 = menu('Would you like to re-run the normalisation with adjusted parameters?', 'Yes','No');
end
end
The issue I have is that, once the user has entered the new parameters in the dialogue box, the xlswrite function is not working to overwrite the previous values and so the user is just repeatedly getting the same result! It throws up no errors so I'm not sure why the xlswrite function isn't working as everything else in the loop seems to work fine...
I've even written a line in to clear the cells before trying to re-populate which is also not working.
Any help gratefully recieved!
  2 Comments
Guillaume
Guillaume on 8 Mar 2019
What is the value of UVNrange?
I don't see the point of the first xlswrite at all, since you immediately overwrite the exact same cells in the next xlswrite. It's just a waste of time.
if after the 2nd xlswrite you're not seeing what you expect in the file, are you sure you're looking at the same file that you're writing to? The cd (which is only executed on the 2nd and late tries) is suspicious. There's normally never any need for cd if you use full paths in your IO calls.
dweather
dweather on 8 Mar 2019
Thanks for this, the first xlswrite i just put in to try and ensure the cells were clear before I tried to populate them. I didn't think it would work tbf..
The cd was what was tripping it up, I have removed it and re-structured how the file path is referenced. Now it works.
Thanks

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!