can i use any loop to concatenate my variables horizintally?, because i have too many variables in workspace and cant wrtie it manually.

1 Ansicht (letzte 30 Tage)
jan=[jan_1958,jan_1959,jan_1960,jan_1961,jan_1962,jan_1963,jan_1964,jan_1965,...
jan_1966,jan_1967,jan_1968,jan_1969,jan_1970,jan_1971,jan_1972,jan_1973,...
jan_1974,jan_1975,jan_1976,jan_1977,jan_1978,jan_1979,jan_1980,jan_1981,...
jan_1982,jan_1983,jan_1984,jan_1985,jan_1986,jan_1987,jan_1988,jan_1989,...
jan_1990,jan_1991,jan_1992,jan_1993,jan_1994,jan_1995,jan_1996,jan_1997,...
jan_1998,jan_1999,jan_2000,jan_2001,jan_2002,jan_2003,jan_2004,jan_2005,...
jan_2006,jan_2007,jan_2008,jan_2009,jan_2010,jan_2011,jan_2012,jan_2013,...
jan_2014,jan_2015,jan_2016,jan_2017,jan_2018];
i have all these variable from jan_1958 to jan_2018 in my work space, and i want to concatenate these variables in one variable say named "jan".
by writing the above code manually is ok. but i want to use any loop instead of putting these variables manually one by one.
i have found a function horzcat but cant understand how to use loop with it
kindly help me to resolve my issue
  6 Kommentare
Daniyal Arif
Daniyal Arif am 16 Aug. 2019
yes it is working but not completly, by this command i get a string like this ('jan_1958' 'jan_1959' 'jan_1960' ......... )
while i want to concatenate these variables horizontally ..
just like in image variable 'jan' is an ouptut after merging theese variables manually ,
problem 2.JPG
Stephen23
Stephen23 am 16 Aug. 2019
Bearbeitet: Stephen23 am 16 Aug. 2019
"can i use any loop to concatenate my variables horizintally?"
There are ways, but accessing variables like that is one way that beginners force themselves into writing pointlessly slow, complex, obfuscated, buggy code that is hard to debug.
"...because i have too many variables in workspace and cant wrtie it manually."
Yes. As Guillaume already explained, it would be much better to fix your code before you end up in the situtation of having lots of variables in your workspace.
"...i want to concatenate these variables horizontally .. "
Sure, that is easy:
  1. Do NOT load your data directly into the workspace: doing that will give lots of separate variables which are awkward and inefficient to work with.
  2. Always load .mat files into an output variable, which is a scalar structure:
S = load(...);
Then you can access the fields of that structure quite easily, without needing to magically access variable names, and then use indexing to allocate that data to an array.
See the answer given to your earlier question:

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by