why does matlab seperate my column of identifiers and row of column headers from the data? what function puts them back together?i have created a new column of data that needs to be put together with the original data, how do i attach that?
3 ビュー (過去 30 日間)
古いコメントを表示
what function will recombine my dataset when matlab automatically seperates my id column and row headers from the data
2 件のコメント
Walter Roberson
2013 年 5 月 14 日
編集済み: Walter Roberson
2013 年 5 月 14 日
How are you reading the data in? Are your headers text strings? Is your data numeric ? When you say you need to put them back together, then are you wanting to produce a text array or a numeric array?
採用された回答
Walter Roberson
2013 年 5 月 16 日
Use the three-output version of xlsread(), and use the third output, "raw". It will reflect what is in the original file.
The first output, the numeric data matrix, will automatically have initial text rows removed (under the assumption that they are column headers) and will also have initial text columns removed. I think it also has trailing rows and columns that are entirely NaN removed. This is because one of the most common operations on an excel file is to work just on the numeric portion, as a numeric array. Numeric arrays cannot have strings in them.
The third output, "raw", will be a cell array, not a numeric array. And that does mean that if you want to extract the numeric subset of it, you are going to have to convert that subset to a numeric array (cell2mat()) if that is the form you want to operate on.
When you go to write out the data, you will be needing a cell array, if you want to have both numeric values and strings.
2 件のコメント
Image Analyst
2013 年 5 月 16 日
編集済み: Image Analyst
2013 年 5 月 16 日
Rereading your question, I think Walter is right - you want the third output: the "raw" cell array. If you use the first two only, they are not aligned since each one starts with the upper left (1,1) at whatever cell in Excel that type of data started. For example your text cells may start at cell A1 ((1,1) of the test cell array = cell A1 of the Excel worksheet), while your numbers cell (1,1) will be cell A2, not A1 (if your numbers start under a row of text column headers).
その他の回答 (1 件)
Image Analyst
2013 年 5 月 15 日
Does it look all separated when you open it up in Excel? If so, then you wrote out the workbook using strings in xlswrite() instead of cells. If the string is inside a cell, then the whole string will be in one Excel cell. If you just used xlswrite to write out strings, then it will put each character into its own cell in Excel. So tell me (1) did you write out the workbook with xlswrite(), and if so, (2) do you have one character per Excel cell?
4 件のコメント
Image Analyst
2013 年 5 月 16 日
Upload your workbook if you want us to take a look at it.. http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!