Info

This question is closed. Reopen it to edit or answer.

Subscripted assignment dimension mismatch.

1 view (last 30 days)
Ashish
Ashish on 4 Sep 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
So I am trying to do this assignment where I have to assign letter grade to given vector percentage (example given [92 86 73 68] my answer should be [A- B C D+ ) . I decided to do this using if...elseif...else statement.
The problem is I also have letter grade which have +,- symbols. For example (B+, D-) etc. So when I have to assign one of these to the given percentage I keep getting the 'Subscripted assignment dimension mismatch.' error.
The thing is if I change B+ or D- to just B and D the program works fine. I feel like the SIZE of my answer increases when I use B+ instead of just B resulting in dimension mismatch somewhere.
What I mean by size:
>> a='B+';
>> b='B';
>> size(a)
ans =
1 2
>> size(b)
ans =
1 1
So yeah how do I make my program read B+ as a size of (1 1) rather than (1 2)
if that is possible...new to Matlab
cheers!

Answers (1)

Star Strider
Star Strider on 4 Sep 2014
Use a cell array instead:
grades = {'A+' 'A' 'A-' 'B+' 'B' 'B-' 'C+' 'C' 'C-' 'D+' 'D' 'D-' 'F'};

Community Treasure Hunt

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

Start Hunting!