How can I concatenate a 2D matrix to a 3D cell array?

3 views (last 30 days)
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
Stefan Bauer
Stefan Bauer on 12 Dec 2018
Hey Bob! Thanks for taking the time to have a look!
When I say that "t1 is a '1x10x201 cell'", I mean that, when I run the code to a breakpoint and hover over the t1 variable, it tells me it's a '1x10x201 cell'. That's literally it. Same for t2. What that actually means is no clearer to me than you.
Generally speaking, you have all the information I have - you can see where and how the RangeGraph variable in the table is made, how I'm accessing it to get t1, and how I've attempted to interface with it. Note to clear up some confusion, though: playerData.RangeGraph is a 4x10x201, from which I'm accessing a specific index (or a specific row of the playerData table) to get t2.
I'll give your suggestion a go in the morning. Generally, though, I think you've correctly identified the issue as my mixing cells and normal matrices, and I should probably just stop trying to use cells and work out how to stick a 3D matrix in a table.
Thanks again!
Bob Thompson
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.

Sign in to comment.

Answers (0)

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!