How do I pick a value in a matrix of characters?
1 view (last 30 days)
Show older comments
Alec Gutmanstein
on 1 Feb 2016
Edited: Alec Gutmanstein
on 1 Feb 2016
I need to do something that is similar to what is seen here: http://www.mathworks.com/matlabcentral/answers/203608-how-to-pick-values-that-is-below-a-certain-value-in-a-matrix-vector
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
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'????
Accepted Answer
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')
More Answers (0)
See Also
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!