copying cells.. I thought it'd be simple

Hi Everyone, Say I have a cell that looks like this: http://imgur.com/RcMRo
I'd like to copy "breakfast" into the next cell down its column UNTIL I hit a completely empty row. At this point, "breakfast" would be in all of the first three rows of the first column.
Then, I would like to proceed to copy dinner down into the next rows until I hit the next completely empty row.. and etc..
in the end the cell should look like this http://imgur.com/q2Unu
Please tell me if I am not explaining this clearly.
My attempt at this lead me through nested loops with calling a function.. and finally a script that basically killed MATLAB as it took 100% of my Processing power (probably because of my unintelligent use of while loops).. Anyway, I was hoping to ask you if you had a easier solution that does not kill my laptop..
Thank you very much!

3 Comments

Jan
Jan on 16 Dec 2012
Edited: Jan on 16 Dec 2012
The images are not clear. It would be much better to explain the data using Matlab syntax like this:
breakfast = {1, 'egg'; 2, 'ham'}
It would be helpful also, if you post the current code. In addition I cannot imagine that you talk about such a tiny system and efficiency. Please post the real size of the data.
Of course an efficient code uses 100% processing tome also, but only for a short time.
Yes it looks like you are talking about tables, not cell arrays. In MATLAB a cell array is a specific thing. Please be clear about what you mean and give some code that can reproduce the data or the essential features.
I apologize! Using Jan's suggestion, mycell looks like this:
mycell= {1,'egg' ; [] 'egg' ; [] 'egg' ; [] [] ; 2, 'ham' ; [] 'ham' ; [] 'ham'}
Here is my thinking, there must need for a cellfun to be in there..
emptyrows=[5] %the row that is all empty in mycell
i=1 %counter
j=2 %counter
while j <= size(mycell,1)
if 1==isempty(mycell{j,1}) && mycell(j,1)~=emptyrows
%If statement wants an empty cell below it but NOT empty row
mycell{j,1}=in{i,1}; %update cell with the previous cell
i=i+1 %continue down the row..
j=j+1 %continue down the row..
elseif 1==isempty(mycell{j,1}) && mycell(j,1)~=emptyrows
i=i+2; %skip down to the next set
j=j+2; %skip down to the next set
else
end
end
GOAL: mycell= {1,'egg' ; 1, 'egg' ; 1 'egg' ; [], [] ; 2, 'ham' ; 2 'ham' ; 2 'ham'}
thank you again.. and yes my data is much bigger than this. More egg and more ham with more blank rows. But I thought if I can make this work... then I can make it work for my real dataset.

Sign in to comment.

Answers (0)

Asked:

on 16 Dec 2012

Community Treasure Hunt

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

Start Hunting!