フィルターのクリア

Matrix to Vectors, Assigning Names to Vectors

16 ビュー (過去 30 日間)
KKR
KKR 2012 年 12 月 30 日
Hope everyone is doing great and are having a happy holidays.
I ran into relatively simple situation (apparently, not so simple for me, as I am new to MATLAB).
I have a Cell structure with 14 elements, with titles of columns (data is exported from Excel, using xlsread function). With that, I have matrix with 14 columns, and I would like to form 14 vectors with name that are member of that Cell.
Of course, I can manually simply do it (in case, that is what I have been doing up until now). I was wondering if I could simply run a loop.
But, when I tried for one vector, it shows the following error.
>> t(1) = MacSales(:,1) ??? Conversion to cell from double is not possible.
Any ideas/suggestions will be greatly appreciated.
Thank yo.
  1 件のコメント
Matt J
Matt J 2012 年 12 月 30 日
編集済み: Matt J 2012 年 12 月 30 日
Auto-naming variables is a dangerous/awkward/discouraged coding practice. Combine your data into a single cell array or use dynamic structure fields.

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

回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 30 日
編集済み: Azzi Abdelmalek 2012 年 12 月 30 日
Title=A(1,:) % A your cell array
B=cell2mat(A(2:end,:))
  2 件のコメント
KKR
KKR 2012 年 12 月 30 日
I think I didnt explain clearly. I actually want the other way around. I have a cell with Titles and Matrix with Data. I would like create vectors which are titled from cell and has data from matrix.
What you have is sort of the reverse of it, i.e. forming a cell with titles and matrix with data.
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 30 日
title={'weight','age'}
M=[60 20;70 25 ;80 30 ;40 14]
A=[title;num2cell(M)]

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


Matt J
Matt J 2012 年 12 月 30 日
for i=1:length(titles)
S.(titles{i})=M(:,i);
end

KKR
KKR 2012 年 12 月 30 日
Great.
Thank you very much. That helps.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by