I currently have 180 matrix variables (1336 x 4) that I would like to make into a structure to make it easier to work with. In the end I want to be able to plot all of this data in the same way on separate plots or subplots.
What is the best way to combine the matrices? I am able to create a structure using 'whos' and then add on a 'data' field of zeros to put the final data in but how would I transcribe all of the variable data into the structure? The variables are not concurrently named so I am struggling to get a for loop to work.

3 件のコメント

Stephen23
Stephen23 2018 年 9 月 4 日
@Kirsty Alsop: the most important question is how did you get those 180 matrices into the workspace? Presumably you did not sit and write them all out by hand, in which case they must have been imported somehow, or generated in a loop somehow... and that is the correct location to fix this problem! If you tell us how these variables first got into your workspace, then we can show you better ways to design your code, so that your data handling is simpler, more efficient, and less buggy.
Magically accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
Kirsty Alsop
Kirsty Alsop 2018 年 9 月 4 日
Unfortunately, this was imported by hand by a colleague and now given to me. They informed me that the matrices were imported from .txt files using the import tool but I have no further info. Hence, I was hoping to streamline the data using a structure. All I currently have is a .mat file with the workspace saved!
Walter Roberson
Walter Roberson 2018 年 9 月 4 日
The best approach would be to not get into this situation, to store the information in a structured manner instead of in separate variables.

サインインしてコメントする。

 採用された回答

Stephen23
Stephen23 2018 年 9 月 4 日
編集済み: Stephen23 2018 年 9 月 4 日

1 投票

You do not say anything about how these variables get into the workspace, so I am going to a guess that they are all contained in one .mat file, in which case the answer to your question is trivially simple:
S = load(...)
If the data are saved/created in some other way, then you please tell us exactly how you got all of those variables into the workspace, and we will show you better methods for handling data.

2 件のコメント

Kirsty Alsop
Kirsty Alsop 2018 年 9 月 4 日
Thank you, I was hoping there would be something simple like this to make it work.
Stephen23
Stephen23 2018 年 9 月 4 日
編集済み: Stephen23 2018 年 9 月 4 日
@Kirsty Alsop: I hope that it helps! You will probably find the function fieldnames to be very useful, and this too:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Get Started with MATLAB についてさらに検索

質問済み:

2018 年 9 月 3 日

編集済み:

2018 年 9 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by