Creating a Matrix from .mat files
7 views (last 30 days)
Show older comments
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 Comments
Image Analyst
on 25 Sep 2016
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
on 25 Sep 2016
Edited: Stephen23
on 25 Sep 2016
"MatLAB will not let me place characters into a 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.
Answers (1)
Walter Roberson
on 25 Sep 2016
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.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!