how can we construct different cells inside cell-array?

2 visualizzazioni (ultimi 30 giorni)
hi there,
I have a cell array of 1x6 size; 6 cell in one rows which contains a data set. Now, I want to construct a 7th cell in which I wanted to store some information regarding experiment. For that, I need to make different cell inside the 7th cell. for instance:
cell_array {1,7} ={ {Date :}, {Name :}, {Exp_time :}, {Remarks : }}
Your help will be greatly appreciated.
Best,
Sushil

Risposta accettata

Voss
Voss il 26 Giu 2022
Perhaps a structure would be useful for storing that information:
exp_info = struct( ...
'Date','2022.06.29', ...
'Name','experiment_1', ...
'Exp_time','00:05:00', ...
'Remarks','Wednesday morning at five o''clock, as the day begins');
Store it in the 7th cell of cell_array, like you plan to:
cell_array = repmat({rand(10)},1,6);
cell_array{1,7} = exp_info
cell_array = 1×7 cell array
{10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {1×1 struct}
cell_array{1,7}
ans = struct with fields:
Date: '2022.06.29' Name: 'experiment_1' Exp_time: '00:05:00' Remarks: 'Wednesday morning at five o'clock, as the day begins'
Or rearrange the thing and store the experimental data in the same structure:
% - one possibility -
exp_info.Results = cell_array(1:6)
exp_info = struct with fields:
Date: '2022.06.29' Name: 'experiment_1' Exp_time: '00:05:00' Remarks: 'Wednesday morning at five o'clock, as the day begins' Results: {[10×10 double] [10×10 double] [10×10 double] [10×10 double] [10×10 double] [10×10 double]}
% - another possibility -
exp_info.Results = cell2struct(cell_array(1:6),sprintfc('Result_%d',1:6),2)
exp_info = struct with fields:
Date: '2022.06.29' Name: 'experiment_1' Exp_time: '00:05:00' Remarks: 'Wednesday morning at five o'clock, as the day begins' Results: [1×1 struct]
exp_info.Results
ans = struct with fields:
Result_1: [10×10 double] Result_2: [10×10 double] Result_3: [10×10 double] Result_4: [10×10 double] Result_5: [10×10 double] Result_6: [10×10 double]
  6 Commenti
Sushil Pokharel
Sushil Pokharel il 27 Giu 2022
So, actually I have a cell array of 1x7: cell_array{1,1:6},cell_array{1,7}. What I am trying to do is I am trying struct_array inside cell_array{1,7} in order to store some information. and what I want is each time when I update the data in cell_array have to store separate information. So that I need struct_array inside the cell_array{1,7} should be increamented by 1.
for instance:
cell_array{1,7}(1)='Flystrain',input('please specify the fly strain: ','s'), ...
'Date',input('mm:dd:yyyy ','s'), ...
'Expt_starttime',input('hh:mm:ss ','s'), ...
'Position_deadflies',input('Enter the position of dead flies: '), ...
'Remarks',input('Note: ','s'));
similarly,
cell_array{1,7}(2)='Flystrain',input('please specify the fly strain: ','s'), ...
'Date',input('mm:dd:yyyy ','s'), ...
'Expt_starttime',input('hh:mm:ss ','s'), ...
'Position_deadflies',input('Enter the position of dead flies: '), ...
'Remarks',input('Note: ','s'));
but things are not working in my way. when I try to store
cell_array{1,7}(2)='Flystrain',input('please specify the fly strain: ','s'), ...
'Date',input('mm:dd:yyyy ','s'), ...
'Expt_starttime',input('hh:mm:ss ','s'), ...
'Position_deadflies',input('Enter the position of dead flies: '), ...
'Remarks',input('Note: ','s'));
it just replace cell_array{1,7}(1). Does it make sense to you? i have tried the recent one which you just send me. still its not working. So, sorry I am killing your time.
Sushil Pokharel
Sushil Pokharel il 27 Giu 2022
Dear voss, I really appreciate your help. thank you so much you are absolutely right. I made a slight mistake in my code. Thank you so once again for your time and your constant help.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by