|
|
Remove structure
Hi,
Is there a simple way to get the names of variables removing their struture?
For exemple, for a structure :
conf.a.name_1 (= 1);
conf.b.name_2 (= 'hello');
conf.c.d.e.name_3 = ([1 1]);
I would like to get 'name_1' 'name_2' 'name_3' so as to define:
name_1 (= 1);
name_2 (= 'hello');
name_3 = ([1 1]);
Thanks
|
|
0
|
|
|
|
Reply
|
Pierre
|
12/9/2009 2:33:01 PM |
|
"Pierre " <pierre.dandre@external.thalesaleniaspace.com> wrote in message
news:hfocet$59b$1@fred.mathworks.com...
> Hi,
>
> Is there a simple way to get the names of variables removing their
> struture?
>
> For exemple, for a structure :
> conf.a.name_1 (= 1);
> conf.b.name_2 (= 'hello');
> conf.c.d.e.name_3 = ([1 1]);
> I would like to get 'name_1' 'name_2' 'name_3' so as to define:
> name_1 (= 1);
> name_2 (= 'hello');
> name_3 = ([1 1]);
DON'T DO THIS.
See Q4.6 in the newsgroup FAQ for an explanation why this is a Bad Idea.
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
|
0
|
|
|
|
Reply
|
Steven
|
12/9/2009 2:48:48 PM
|
|
>
> DON'T DO THIS.
>
> See Q4.6 in the newsgroup FAQ for an explanation why this is a Bad Idea.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
Thanks for the quick and logical answer. In fact, I want to get the name only and dont want to assign it. In the example, I would like to get the strings 'name_1' 'name_2' 'name_3'.
If I have well understood the purpose of the fieldnames function, I can only look at "level" 1. I woud have 'a' 'b' 'c' with my example. In my case, I don't know the number of "levels" in my structure, which can vary from one chain to another one.
|
|
0
|
|
|
|
Reply
|
Pierre
|
12/9/2009 3:19:02 PM
|
|
> DON'T DO THIS.
>
> See Q4.6 in the newsgroup FAQ for an explanation why this is a Bad Idea.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
Thanks you for your quick and logical answer.
In fact, I would like to get the names only, that is to say 'name_1', 'name_2' and 'name_3' in my previous example.
I don't know if the function fieldnames can easely deal with it. It seems to me that it only provides the "level 1" names (i.e. 'a' 'b' 'c' in my example). As I don't know the number of levels of the structure (which can vary from one "branch" to another), I can't simply use the fieldnames function.
Thks, Pierre
|
|
0
|
|
|
|
Reply
|
Pierre
|
12/9/2009 3:32:03 PM
|
|
"Pierre " <pierre.dandre@external.thalesaleniaspace.com> wrote in message
news:hfof56$4hj$1@fred.mathworks.com...
>>
>> DON'T DO THIS.
>>
>> See Q4.6 in the newsgroup FAQ for an explanation why this is a Bad Idea.
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>> comp.soft-sys.matlab (CSSM) FAQ:
>> http://matlabwiki.mathworks.com/MATLAB_FAQ
>>
> Thanks for the quick and logical answer. In fact, I want to get the name
> only and dont want to assign it. In the example, I would like to get the
> strings 'name_1' 'name_2' 'name_3'.
>
> If I have well understood the purpose of the fieldnames function, I can
> only look at "level" 1. I woud have 'a' 'b' 'c' with my example. In my
> case, I don't know the number of "levels" in my structure, which can vary
> from one chain to another one.
The "DON'T DO THIS" was in reaction to your comment that "I would like to
get 'name_1' 'name_2' 'name_3' so as to define:". If you just want the
strings, not to create variables, then use dynamic field names and
recursion, something like:
conf.a.name_1 = 1;
conf.b.name_2 = 'hello';
conf.c.d.e.name_3 = [1 1];
fn = fieldnames(conf);
for whichfield = 1:numel(fn)
fprintf('Processing conf.%s\n', fn{whichfield});
if isstruct(conf.(fn{whichfield}))
fprintf('nested struct -- need to recurse\n');
else
fprintf('leaf node -- no need to recurse\n');
end
end
Make a function out of the last piece of this code so you can recurse down
the structure 'tree'.
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
|
0
|
|
|
|
Reply
|
Steven
|
12/9/2009 3:59:59 PM
|
|
|
4 Replies
390 Views
(page loaded in 0.034 seconds)
Similiar Articles: Remove small objects from binary image without erode. - comp.soft ...Is there a function that removes objects binary image based only on their pixel area? I want to maintain lines, so erode or close is out of the q... Gaussian noise removal - comp.soft-sys.matlabfunction for haze removal from images - comp.soft-sys.matlab ... Gaussian noise removal - comp.soft-sys.matlab For removal of gaussian noise from the image, i tried using ... DC removal flter - comp.soft-sys.matlabRemoving a Drifting Baseline ... Did the filter not work or did it not remove the drift? ... DC removal flter - comp.soft-sys.matlab function for haze removal from ... Comparing bwmorph(image, 'remove') and edge(image, 'roberts ...Remove structure - comp.soft-sys.matlab Comparing bwmorph(image, 'remove') and edge(image, 'roberts ... Remove structure - comp.soft-sys.matlab Comparing bwmorph(image ... remove row if contains NaN - comp.soft-sys.matlab... continued > > > I want to : > > if row contains NAN, remove row completely so i end up with : > 1 97 > 1 47 > 2 13 > 2 97 > 2 47 > > What function can i ... function for haze removal from images - comp.soft-sys.matlab ...Hello guys, Are there any functions in Matlab for image haze removal ? Please let me know..... thanks kate ... "Incorrect structure found in PDF file" - comp.text.pdfCreate a new profile, go into the fixup pane, and pick one that's named "Remove document structure". Add that to your newly cerated profile and give the profile a ... How to remove file extension? - comp.soft-sys.matlabHow can i remove the ".tiff" file extension? Because i just want to get the filename ... Then use the fullfile() function to reconstruct it without the extension. Remove first and last 3 characters of a string - comp.soft-sys.sas ...You can use LENGTH() function to determine how long the string is then use SUBSTR() function to capture the range of the characters you want to keep. Wavelet coefficients - comp.soft-sys.matlabremove backgroud using global threshold - comp.soft-sys.matlab ... wavelet compression function in Matlab? - comp.compression ..... 1-D or 2-D) obtained by wavelet ... Remove fields from structure - MATLAB - MathWorks - MATLAB and ...This MATLAB function removes the specified field from the structure array s. remove functionRe^3: remove function by ikegami (Pope) on Jan 29, 2009 at 21:29 UTC. A function that deletes both files and directories? It wouldn't work on operating systems that ... 7/28/2012 12:16:20 AM
|
|
|
|
|
|
|
|
|