Moving the contents in the cell array
36 次查看(过去 30 天)
显示 更早的评论
data = {'abc' , 'def' , 'ghi'}
I have a cell array named data. Now i need to move the contents to another index in the same array and delete the older contents.
for example: data([4 5 6]) = data
This will give the result as data = {'abc' , 'def' , 'ghi', 'abc' , 'def' , 'ghi'}. Instead of this i just need to move the contents based on the index number and empty the contents in the older position.
Answer should be like this,
data = {[],[],[],'abc' , 'def' , 'ghi'}
How can i do it?
Thanks a lot
0 个评论
回答(4 个)
Stephen23
2016-9-2
编辑:Stephen23
2016-9-2
>> data = {'abc' , 'def' , 'ghi'};
>> data(4:6) = data;
>> data(1:3) = {[]}
data =
[] [] [] 'abc' 'def' 'ghi'
OR
>> data = [repmat({[]},1,numel(data)),data]
data =
[] [] [] 'abc' 'def' 'ghi'
OR
>> data(4:6) = {[]};
>> data = circshift(data,[1,3])
data =
[] [] [] 'abc' 'def' 'ghi'
OR
>> tmp = {[]};
>> data = circshift([data,tmp([1,1,1])],[1,3])
data =
[] [] [] 'abc' 'def' 'ghi'
OR
>> data(2,:) = {[]};
>> data = reshape(flipud(data)',1,[])
data =
[] [] [] 'abc' 'def' 'ghi'
OR
>> data = repmat(data,1,2);
>> data(1:3) = {[]}
data =
[] [] [] 'abc' 'def' 'ghi'
0 个评论
Azzi Abdelmalek
2016-9-2
data = {'abc' , 'def' , 'ghi'}
data1([4 5 6])=data
4 个评论
Bachtiar Muhammad Lubis
2019-1-10
how if we have a cell that contains binary image or another image. how can we move that image that was stored o a new variable? so that we can show it using imshow().
Walter Roberson
2019-1-10
new_variable = name_of_cell{row_index, column_index};
imshow(new_variable)
but note that imshow() would be happy with
imshow( name_of_cell{row_index, column_index} );
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!