concatenate mutiple tables repetative

Hello
I have a very large number of individual tables at my workspace, and I would like to concatenate them into a larger one by vertically combining all of them.
I have seen vertcat but i think it doesn't do so many repetition
The form of the final table is supposed to be =[A;B;...;n], does any body know of a way to automatically concatenate them.
the tables are generated into the workspace after some data manipulation of some .netCDF files, each table has been assigned a name automatically e.g. W1, W2.....Wn.
I had the tables into a structure (struct 1x1), but due to certain conditions had to individually extract them and save them assigning them with a timestamp, so now they are on the workspace as a table of 1603x561.
So all the tables are exactly the same dimension but my problem is how to automatically combine them vertically
thanks
george
p.s. the questioned is a re-post unfortunately the previous answer was not working ,thank though for the contribution in adnvance

11 commentaires

Azzi Abdelmalek
Azzi Abdelmalek le 16 Oct 2013
Give a short example for w1. Is w1 a struct array or something else
dpb
dpb le 16 Oct 2013
Again, it's far better to not use individual variable names like W1,W2,...Wn in Matlab -- it makes for such problems of writing dynamic-evaluated code which brings in evil eval
Would be better to keep the structure format w/ named fields or us a variably-sized cell array to hold the individual Wi or similar solution. Then the generalization is usually fairly trivial...this way it's a pain in the proverbial appendage.
George
George le 16 Oct 2013
Modifié(e) : George le 16 Oct 2013
the tables were created by manipulation and their are separate tables in the workspace, not in a struct array. Each table has value 1603x561
any ideas on how to do a repetitive process for these table? I can change the naming of the table from W_01 to W1 if it more convenient
thanks
dpb
dpb le 16 Oct 2013
Yeah, and they're all bad...how/why did you create different names? Show a short code snippet...
WX=Usp.u1; WY=Vpr.v1; W_00=[WX;WY]; clear WX WY %
for i=1:s2;
eval(['WX=Uspeed.u',num2str(i),';']);
eval(['WY=Vprofile.v',num2str(i),';']);
eval(['W_',num2str(i),'=[WX;WY]',';']);
end
Unfortunately i need to name them in order to keep track of the different measurements. Because all these tables represent measurements from different days
You can use dynamic field names instead of eval
S.(['hello' num2str(1)]) = 'world'
George
George le 16 Oct 2013
i didn't know that, thanks for the tip :)
But the issue here is after having all these tables how do i vertically concatenate them?
dpb
dpb le 16 Oct 2013
Go back a step and follow the advice above. Get rid of the names of the variables and use structure field names or cells with a corresponding identification field. Anything but what you've done almost would be better.
Then you can operate on the structure names or the cell arrays or whatever but as long as you persist in the different names you've doomed yourself to having to continue to do such nasties as you've done and it only gets worse as you've discovered...
George
George le 16 Oct 2013
It was essential that the tables were created, and given separate names, after that a time stamp had top be created, and several plots had to be made per interval. Now I m at the stage where all the new tables have to be combined in a S=[A;B] format and I am searching an option that will handle all the table together and then save them
dpb
dpb le 16 Oct 2013
Modifié(e) : dpb le 16 Oct 2013
It was essential that the tables were ... given separate names
I don't believe that for a minute... :) That all could have been done in different manner. At least two better alternatives of named structure fields or cell arrays have been posited regardless of version. A third if you have a late release.
One alternate solution would be to go back to the beginning before you split them all up and just create the whole thing from the git-go and forget about the current W* arrays entirely.
By this I mean you could leave your existing code up to this point that works for the plots and all but instead of then trying to smush all these together that as you've discovered isn't simple just say
clear W*
to free up memory and then build the full data set from the files again. This is somewhat inefficient in that it is redundant, yes, but it lets you get from where you are to where you want to go and you can then if this is going to be a repeating future need make the modifications in your existing code without that being on a critical path to finishing this dataset.
Whatever you do, it is just going to be plain ugly and get uglier all the time to continue this route.
The only way out from here is eval or writing them all out explicitly in a try...catch...end block to handle any non-existant ones, etc. or other equally bad (or even worse) choices.
Stephen23
Stephen23 le 21 Oct 2019
Modifié(e) : Stephen23 le 21 Oct 2019

Connectez-vous pour commenter.

Réponses (2)

Sean de Wolski
Sean de Wolski le 16 Oct 2013

0 votes

Are these "tables" actual table datatypes? If they are then you can use innerjoin/outerjoin/stack etc.
If they are not, then you might want to consider using tables instead (new in R2013b).
Azzi Abdelmalek
Azzi Abdelmalek le 16 Oct 2013
Modifié(e) : Azzi Abdelmalek le 16 Oct 2013
It's recommanded to generate one variable w instead of w1,w2,...
If you have no choice to do it, you can try this:
n=5
s=['w=[' sprintf('W%d;',1:n) ']']
eval(s)

Catégories

En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange

Question posée :

le 16 Oct 2013

Modifié(e) :

le 21 Oct 2019

Community Treasure Hunt

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

Start Hunting!

Translated by