Matlab dimensions must agree error. What's going on? -


I am getting:

Error in using == ... matrix Dimensions must be agreed. Error (line 9) - if move2 == 'south'

What's going on?

  disp ('Welcome Dr. Doffenheimers.'); Move1 = input ('You are in room number 1. Do you want to take the West or the answer?:', 'S'); If move1 == 'reply' disp ('now you are in room 4.'); Move2 = Input ('Would you go south or east?:', 'S'); If move2 == 'south' disp ('you are back in room 1.'); Athif 2 steps == 'East' Disp ('Now you are in room 5'); And disp ('There is no door there. You are still in the room 4.'); Although the two parameters that you are comparing are the string of characters, although the interval  

But in MATLAB you can not compare the letters of only two letters with different array sizes. Array dimensions should agree to that case. Daniel in your case has suggested that you can use any of the following:

strcmp () - compares strings with regard to their case.

strcmpi () - Comparison of cases

This command gives a logical value (either 0 or 1) - if the match is found then value 1 (true) otherwise 0 (wrong) will be.

I re-code for you:

  disp ('Welcome Dr. doffenheimers.'); Move1 = input ('You are in room number 1. Do you want to take the West or the answer?:', 'S'); P = strcmpi ('Answer', move 1); If P == 1 disp ('now you are in room 4.'); Move2 = Input ('Would you go south or east?:', 'S'); Z = strcmpi ('south', move2); If z == 1 disp ('you are back in room 1'.); Else z = strcmpi ('east', move 2); If z == 1 disp ('now you are in room 5'); And disp ('There is no door there. You are still in the room 4.'); 

Hope this will work.

div>

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -