![]() As you will find, functions like ischar that test whether a single variable is a string, don't work so well on cell array. To do this, we need to know which cells contain numbers.First, we copy over everything that's already a number, then we convert the rest to numbers and copy them the same way. Our basic plan is to copy all the data over to a new array in two pieces.This would be really painful to do with a loop, but if you know how to do it with a loop, and that's the only way you know how to do it, then use a loop! Go for a solution that works before you waste to much time on being elegant.It took me several minutes to work out how it had to be done. ![]() Why do we solve the problem like this? Or better yet: what should our thought process be when we approach such a problem? Some thoughts: Strtype = %apply the ischar function to every element of rawĭat(~strtype) = cell2mat(raw(~strtype)) %copy over cells that are already numbersĭat(strtype) = str2double(raw(strtype)) %convert non-numeric cells to numbers, then copy If we used the xlsread option, we can do some data cleaning (advanced): dat=nan(size(raw)) %make an empty cell array Both are indexed from 0, so that the arguments 1 and 0 above mean to start at the second row, first column. The two extra arguments supplied are the row and column at which to start.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |