MATLAB Answers

How to Pad Cell Array to make dimensions consistent?

18 views (last 30 days)
Ibro Tutic
Ibro Tutic on 24 Jul 2017
Answered: Ibro Tutic on 24 Jul 2017
Not sure if I am using the right terminology here, but I have a cell array that comes from user input. When the data is input, it comes in as numbers separated by commas (fairly small at max 2 numbers). There are 13 places to input numbers which corresponds to 13 rows in a cell array. I split the data into a 13x2 cell array using
split1=regexp(data, ',' , 'split')
verify=vertcat(split1{:})
This works perfectly when all of the data comes in as two numbers separated by commas, however, in some cases only one number will be entered, which causes issues when using vertcat. My idea was to just repeat this single number twice so the data can still be passed into 'vertcat' without issues, but I'm not sure how to go about this. Doing this will not affect my final output in anyway and I think it is the easiest method. I attached a sample .mat file that shows the test case that I am working with.
Possibly something like this:
for i=1:length(split1)
if length(vertcat(split{i})) == 1
%somehow repeat single value twice
else
verify(i,:)=vertcat(split{i})
end
end
Thanks for any help.

  0 Comments

Sign in to comment.

Accepted Answer

Ibro Tutic
Ibro Tutic on 24 Jul 2017
My idea worked. It's fairly crude but it should work. Thanks for viewing!
split1 = regexp(runs, ',', 'split');
for i=1:length(split1)
if length(vertcat(split1{i})) == 1
verify(i,:) = [split1{i} split1{i}];
else
verify(i,:)=vertcat(split1{i});
end
end

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by