How do I pick a value in a matrix of characters?

1 view (last 30 days)
I generated a matrix by the following:
field = ones(height,width) .* 'O';
field = char(field);
And then I have some code to have a M in the top left field and another spot that varies depending on user input. I need to be able to select just the values of the field that are 'M'
  1 Comment
Image Analyst
Image Analyst on 1 Feb 2016
"I need to be able to select just the values of the field that are 'M'" <== wouldn't those just simply have values of 'M'????

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 1 Feb 2016
Assuming you mean the "locations" rather than "values" of the M's, try this:
height = 6;
width = 3;
field = ones(height,width) .* 'O';
field = char(field)
field(2, 3) = 'M';
field(4, 1) = 'M';
[rows, columns] = find(field == 'M')
  1 Comment
Alec Gutmanstein
Alec Gutmanstein on 1 Feb 2016
Edited: Alec Gutmanstein on 1 Feb 2016
You assumed correct. I have to be able to control/manipulate the location of M's. This should do the trick. Thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Multidimensional Arrays 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!