How can I concatenate a 2D matrix to a 3D cell array?
3 views (last 30 days)
Show older comments
As part of an ongoing project, I have a table of data, one value of which is a 3-dimensional cell array:
ID = [];
Class = [];
miscellanious_crap = [];
RangeGraph = cell(size(PlayerData, 1), stepsToTrack, pointNum);
% RangeGraph = cell(4, 11, 201);
% ...
% Code in which I fill in all the other values of the table, etc.
% ...
%
playerData = table(ID, Class, miscellanious_crap, RangeGraph);
This is, essentially, the data for a bunch of 3D graphs; Each player gets a surface of the change of that 201-point line over a rolling period of 11 samples back.
In another bit of code, elsewhere, I access this, in order to strip one set of 201 points off one end and put a new set on the front. In theory.
Unfortunately, between multi-dimensional arrays and cells I just cannot work out how to do this.
% Using a fuzzy inference system, I get a 201-point line.
% Don't worry about it, just understand that ARR is an X-by-201 matrix.
inputs = [playerData.DPS_Melee(index) playerData.DPS_Close(index) playerData.DPS_Mid(index) playerData.DPS_Long(index) playerData.DPS_VLong(index)];
[output,IRR,ORR,ARR] = evalfis(inputs, rangeEvalSys, pointNum);
% Then, I want to pop off the first element of the player's array of RangeGraphs, and stick ARR on the end.
t1 = playerData.RangeGraph(playerIndex, 2:end, :);
t2 = rot90(ARR);
% t1 is a '1x10x201 cell'
% t2 is a '1x201 double'
% t3 = cat(2, t1, t2);
% "Dimensions of matrices being concatenated are not consistent."
% for i = 1:10
% t3(1, i, :) = t1(1, i, :);
% end
% t3(1, 11, :) = t2(1, :);
% "Conversion to cell from double is not possible."
Any help would be enormously appreciated. I'm a bit stumped.
3 Comments
Bob Thompson
on 12 Dec 2018
The power of cells is that you can put anything into them (doubles, strings, structures, arrays of doubles, etc.). If each of your cells just contains a single double value then, yes, it is useless to put your self through the pain of using cells. You can try and test if this is possible by using cell2mat() to convert RangeGraph into an array of doubles.
If that doesn't seem to be possible, the I would suggest a couple of other things.
1) Change RangeGraph to have players as the third dimension.
RangeGraph = cell(stepsToTrack, pointNum, size(PlayerData, 1));
It's not going to change anything else drastic, though you will need to double check indexes are now applied correctly, but I think it will help visualize the data organization better, as each t1 will now be in rows and columns, rather than columns and sheets. (I.e. each player has a sheet.)
2) Use num2cell(t2) before you try and cat in order to convert t2 into a cell array. This should help your issue of mixing array types.
Answers (0)
See Also
Categories
Find more on Matrices and Arrays 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!