Change the name of structure inside a cell

Hello,
I got the cell names stuff with 2 field values. When I open "stuff" i see a message "1x1 struct", can i change this display to like say "1x1 NAMEIWANT"?
names = {'f1', 'f2'};
values = {1 2};
args=[names;values];
structure = struct(args{:});
stuff{1,1} = structure;
stuff{1,2} = structure;
Thanks for your time, happy holidays

3 Kommentare

madhan ravi
madhan ravi am 18 Dez. 2018
"1x1 struct"
is the type of class not the name itself
Tiago Dias
Tiago Dias am 18 Dez. 2018
ok, so how can I make something like these?
Picture 1.PNG
Jan
Jan am 18 Dez. 2018
@Tiago: It is not meaningful to create a kind of table, which contains such an output for the given input. "1x1 fsrModel" is nothing, which explains the contents in a meaningful way in the data browser. This tool is designed to show the class of the variable and then "1x1 struct" is perfect. If you want to display something else, create you own uitable in a GUI, but not the standard browser for data.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Guillaume
Guillaume am 18 Dez. 2018

0 Stimmen

In your screenshot, mlrModel, fsrModel, etc. are the name of classes. They may look like structures but these things are absolutely not structures, they're objects, instances of classes. In order to get a mlrModel you would have to call whichever function creates such objects, possibly the class constructor, with the appropriate inputs. While matlab provides a way to convert objects to structures there is no reverse operation other than what is provided explicitly by whomever wrote these classes.
In conclusion, look at the documentation of whatever library you're using to find out how to create these objects. They're not structures.

8 Kommentare

Tiago Dias
Tiago Dias am 18 Dez. 2018
Oh ok. Is there any way i can create the classes after the creation of the cell called stuff?
Image Analyst
Image Analyst am 18 Dez. 2018
You can create a class with whatever name you want.
Stephen23
Stephen23 am 18 Dez. 2018
I doubt that creating different classes just for the purposes of displaying something is really the path that you want to be going down.
Easier to write your own display using uitable or something similar.
but how? i want the 1st colum do have a name and the 2nd column of stuff to have other
classdef Bananas
properties
names
values
end
methods
names = {'f1', 'f2'};
values = {1 2};
args=[names;values];
structure = struct(args{:});
stuff{1,1} = structure;
stuff{1,2} = structure;
end
end
this does not start to run, i have red lines all over classdef properties methods
Image Analyst
Image Analyst am 18 Dez. 2018
What is wrong with the names mlrModel, pcrModel, etc. Why do you want to change them?
thats is just an example, because i thought that i could change 1x1 struct to 1x1 "whatever i want".
in the example i got a cell with 2 columns and it appears 1x1 structure, i would like to write for column 1 "1x1 bananas" and for column2 "1x1 pineaple" for example.
i turnarounded by transforming stuff into a table and then assign with
table = cell2table(stuff)
table.Properties.VariableNames = {'bananas','pineaple'}
Guillaume
Guillaume am 18 Dez. 2018
Tiago, I think you need to backtrack a bit. All this display we've been talking is with the variable browser and command line display. They are designed to show you the class of whatever is stored in the cell array (unless it's a small enough matrix or char array) because that's what useful for writing and debugging code.
So, what is your use case? You seem to be using that display for other purpose. Perhaps you should be using a GUI instead as suggested by Stephen.
Jan
Jan am 18 Dez. 2018
Bearbeitet: Jan am 18 Dez. 2018
uitable('Data', {'Name 1', 17.3, 'fsrModel'; 'Name 2', 3.14, 'fsrModel'})

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Tiago Dias
Tiago Dias am 18 Dez. 2018

0 Stimmen

@Stephen Cobeldick the objective was just when i open "stuff" to see that the column 1 is label with a specific name and column 2 is label to another name

1 Kommentar

Jan
Jan am 18 Dez. 2018
@Tiago: This is the section for answers. Please post comments as comments. Thanks.
Then problem is hidden in "just when I open". Opening a variable in the WorkspaceBrowser has a specific purpose. You ask for a method to create a special class just to missuse the WorkspaceBrowser to show a wanted output. This is indirect ond too complicated, because as said already it is much easier to create a new GUI instead of using the WorkspaceBrowser. Then you have the complete freedom to display what you want.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 18 Dez. 2018

Bearbeitet:

Jan
am 18 Dez. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by