Updation of Cell Array

I have a matrix of 100*400.I need to read a cell(from matrix), take its field as store it as a structure, update one field in the structure and put this new data back to the original cell with all the fields present, but only the updated field is present.Also, horizontal concatenation did not work out.Can I get any help regarding this?Thanks in advance!

1 个评论

Your question title speaks of cell array, you then state that you have a matrix, then talk about structures. These are 3 different things, so it's really unclear what you're asking.
Please provide a small example of input and desired output. Also when saying that something doesn't work provide the (erroneous) code you're using and the full text of the error message.

请先登录,再进行评论。

 采纳的回答

per isakson
per isakson 2019-8-9
编辑:per isakson 2019-8-9
Is something like this what you are looking for? I don't quite understand what you tried.
Try this code
%% Sample data
cell_array = cell( 100, 400 );
ix_row = 117;
ix_col = 314;
S = struct( 'f1', 1, 'f2', 2, 'f3', 3 );
cell_array{ ix_row, ix_col } = S;
%% reference the content of cell(ix_row,ix_col)
>> sas = cell_array{ ix_row, ix_col }
sas =
struct with fields:
f1: 1
f2: 2
f3: 3
%% Update one field of the struct in the cell(ix_row,ix_col)
>> sas.f2 = 200;
>> cell_array{ ix_row, ix_col } = sas;
>> cell_array{ ix_row, ix_col }
ans =
struct with fields:
f1: 1
f2: 200
f3: 3

6 个评论

Yes.I have done similar to this.But other than the updated field, no other field is retrievable.
I don't get you. The values of the fields, 'f1' and 'f3', are retrievable.
>> cell_array{ ix_row, ix_col }.f1
ans =
1
>> cell_array{ ix_row, ix_col }.f3
ans =
3
Or what do you mean by "other fields"?
An alternate way of modifying the value of one field
>> cell_array{ ix_row, ix_col }.f2 = 300;
cell_array = cell( 100, 400 );
x_row = 117;
Picking the value, 117, outside the interval, [1,100], was a mistake by me.
I agree, f1 and f3 must be retrievable.But I am unable to do so.Thats the issue.
"But I am unable to do so [i.e. retrieve the values of the fields, f1 and f3]" It's hard for me to tell why, since you provide so little information. I have no problem doing it in my example and I assume that you can successfully repeat my example. (I use R2018b.)
Show
  • the value of the cell in question before the update (I assume it's a struct.)
  • statement by statement how you update one field of the value of the cell in question
  • the value of the cell in question after the update
  • statement by statement how you try to retrieve the values of the fields that you didn't update
OK.Thank you so much for the help!

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by