MATLAB Answers

Moving the contents in the cell array

128 ビュー (過去 30 日間)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2016 年 9 月 2 日
コメント済み: Walter Roberson 2019 年 1 月 10 日
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 件のコメント

サインイン to comment.

回答 (4 件)

Stephen Cobeldick
Stephen Cobeldick 2016 年 9 月 2 日
編集済み: Stephen Cobeldick 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 件のコメント

サインイン to comment.


Azzi Abdelmalek
Azzi Abdelmalek 2016 年 9 月 2 日
data = {'abc' , 'def' , 'ghi'}
data1([4 5 6])=data

  4 件のコメント

表示 1 件の古いコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 9 月 2 日
then just write
data=data1
Bachtiar Muhammad Lubis
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
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} );

サインイン to comment.


KSSV
KSSV 2016 年 9 月 2 日
data = {'abc' , 'def' , 'ghi'} ;
iwant = cell(1,6) ;
iwant(4:6) = data ;

  1 件のコメント

Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2016 年 9 月 2 日
I want to move it in the same cell array. Not by shifting it to another new cell array

サインイン to comment.


KSSV
KSSV 2016 年 9 月 2 日
data = [cell(1,3) data]

  2 件のコメント

Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2016 年 9 月 2 日
If i get the index as [4 7 9] then above does it work. I will get the random index and based on the index number i need the place the contents in the cell array
KSSV
KSSV 2016 年 9 月 2 日
That case you have to initialize the cells empty with some name...and replace your data with the indices...like get iwant and rename it as data again...

サインイン to comment.

サインイン してこの質問に回答します。


Translated by