The code I'm currently trying to build depends on the user using the correct letters, corresponing x and y. So what I want to do is to create an error-message for when the user does not use x & y, and then prompts him to try again. I have this so far:
coord=input('Enter an x and a y coordinate on the form x3 y4: ','s');while sum(isletter(coord))~=2 coord=input('Please only write one letter for x and y, try again: ','s');endwhile strfind(coord,'x')>strfind(coord,'y') coord=input('Please enter x before y, try again: ','s'); endcoord=strtrim(coord); %eliminates blanks before and after
[xval,yval]=strtok(coord); %Splits coord in two
[xval,~]=strtok(xval,'x'); %gives only the number in variable
[yval,~]=strtok(strtrim(yval),'y');pause(1)% while strfind(coord,'x')==[] && strfind(coord,'y')==[]
% coord=input('Please use the letters x and y accordingly, try again: ','s');
% end
fprintf('You have chosen the coordinates (%s,%s)\n',xval,yval) x=str2double(xval);y=str2double(yval);plot(x,y,'ko','MarkerFaceColor','k')grid on
I want the commented part to work somehow. I want the program to be able to recognize the letters in the input and determine if they are the right ones basically.
Any suggestions?
Best Answer