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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by