0
votes

I'm quite new to programming (MatLab) and I have a question.

I have a character matrix, consisting out of 500 rows and 81 columns. I would like to transform this matrix into a vector with 500 rows. Each row having 81 characters.

If i try the following:

for i = 1:length(CharMatrix)
    CharVect(i) = CharMatrix(i,:) 
end

it gives the error: "Subscripted assignment dimension mismatch"

What am I doing wrong?

1
What do you think the difference between a matrix and a vector is? - Dan
So, you want to be able to index an entire row of characters with only one index is that it? Why can't you use two as you're doing? What do you want to use this for? You might want to have a look at cells. - Stewie Griffin
Maybe I wasn't clear enough. I have 500*81 characters. I want to transform these 500 rows with 81 characters to 500 double vectors, so i can use some calculations on them. If I have a single row of 81 characters, I can use the function [str2num(CharVector(:))]'. - asdfgqwer

1 Answers

0
votes

(given your clarifications), this might be the solution for you:

res = zeros(length(CharMatrix),1)
for i=1:length(CharMatrix)
    res(i) = str2num(CharMatrix(i,:))
end

no need to create CharVect explicitly.