Creating a Matrix from .mat files

7 ビュー (過去 30 日間)
N/A
N/A 2016 年 9 月 25 日
回答済み: Walter Roberson 2016 年 9 月 25 日
Hello. I am working on a project to search a matrix of values. We have been given three .mat files. One with names of materials, one with material properties, and one with the values corresponding to the material and the specific property. I am trying to combine these all into one matrix, which will allow me to search for the minimum and maximum values of each property. MatLAB will not let me place characters into a Matrix and I am unsure what to do. Does anyone have any ideas?
  2 件のコメント
Image Analyst
Image Analyst 2016 年 9 月 25 日
You forgot to attach the 3 mat files. How many variables are in each mat file? What are their types and shapes (e.g. a structure, a 1000-by-4 double array, and a character string)? Which of them do you want to combine into a single array? How many dimensions would that array be?
Stephen23
Stephen23 2016 年 9 月 25 日
編集済み: Stephen23 2016 年 9 月 25 日
"MatLAB will not let me place characters into a Matrix"
Yes it will. Character arrays are a basic data type in MATLAB. Here is a character matrix:
>> X = ['Hello';'World']
X =
Hello
World
>> X(2,:)
ans =
World
And it is easy to allocate the character values to a numeric matrix, if that is what you wish to do:
>> Y = zeros(2,5);
>> Y(:) = X(:)
Y =
72 101 108 108 111
87 111 114 108 100
So whatever you are doing has nothing to do with whether MATLAB can store characters in a matrix (it can). However you have only given very general information about what you are doing, and no information at all about how the data is formatted. So until you actually give us some useful information about the data and how you want it to be loaded, here is some general advice:
  • load your data in a way that suits your data.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 9 月 25 日
If you have a cell array of strings, S, then you can use
matlab.lang.makeUniqueStrings(matlab.lang.makeValidName(S), 63)
to generate unique names that are valid MATLAB identifiers. Those names can then be used to construct a table() object as the VariableNames and the RowNames, after which you can index the table by those unique names.
Alternately, you could use containers.map to create an object indexed by the strings themselves.
But more typically what you would do is leave the data as a numeric array, and when you get a query, use ismember() between the query string and the list of valid strings in order to find the index of the string in the list, and then use that index to access the numeric array.

カテゴリ

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