Extraction of individual matrix from cell array

45 ビュー (過去 30 日間)
Praveen Kumar Ramani
Praveen Kumar Ramani 2019 年 2 月 1 日
編集済み: Guillaume 2019 年 2 月 1 日
I want to extract all the matrix in cell array as individual matrix in my workspace
MT1=Microtrips{1,1}
MT2=Microtrips{1,2}......
MTn=Microtrips{1,n}
Plz find attached mat file
help me out with the code
  4 件のコメント
Stephen23
Stephen23 2019 年 2 月 1 日
編集済み: Stephen23 2019 年 2 月 1 日
@Praveen Kumar Ramani: both of those will be much simpler with indexing. Do you have any relevant reason why you need to force yourself into writing slow, complex, buggy code?
Guillaume
Guillaume 2019 年 2 月 1 日
編集済み: Guillaume 2019 年 2 月 1 日
Gah! You've already asked this question, been told not to do that and shown how to use your cell array efficiently. So wy do you persist?
Of course, now that you've been shown a way to do it you've accepted it. Except as you've been told repeatedly, it makes your life harder not easier. Sure enough, as predicted, your next question is how do I use all these variables that I've pointless created. Well, you can't easily because you've done exactly what we told you not to do.
If you don't listen to our advice why should we bother answering you.

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

回答 (2 件)

KSSV
KSSV 2019 年 2 月 1 日
編集済み: KSSV 2019 年 2 月 1 日
Praveen Kumar Ramani it is a bad idea to save each cell into individual matrix.....infact you need not to do it. It is waste of memory and waste of time. Already you have your information in hand in a proper and neat way. You can extract any value you want using :
for i = 1:length(Microtrips)
iwant = Microtrips{i}
end
  4 件のコメント
Praveen Kumar Ramani
Praveen Kumar Ramani 2019 年 2 月 1 日
i want all cell as individual from 1 to n
KSSV
KSSV 2019 年 2 月 1 日
YOu have that already in hand....
for i = 1:length(Microtrips)
Microtrips{i}
end

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


Mundrathi Venugopal
Mundrathi Venugopal 2019 年 2 月 1 日
After loading the mat file,I guess you would probably wanna do this.
for i=1:numel(Microtrips),eval(['MT' num2str(x) ' = Microtrips{' num2str(x) '};']);end
However, Many common uses of the eval function are less efficient and are more difficult to read and debug than other MATLAB functions and language constructs.
  2 件のコメント
KSSV
KSSV 2019 年 2 月 1 日
It is not suggested to use eval.
Stephen23
Stephen23 2019 年 2 月 1 日
"...I guess you would probably wanna do this."
Or you could read the MATLAB documentation, which states "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended. The preferred method is to store related data in a single array".
Good luck with your pointlessly slow, pointlessly complex code!

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by