0

I have a text file that is a matrix 2819x10. I have splited it into 5x5x563 matrix using code below

Matrix = dlmread('det.txt');
for j=1:1:563
for i=1:1:5

M(i,1,j) = Matrix(temp,3);
M(i,2,j)= Matrix(temp,4);
M(i,3,j)= Matrix(temp,5);
M(i,4,j) = Matrix(temp,6);
M(i,5,j) = 1;
temp=temp+1;
end
end

After this code I have Matrix 5x5x563. Right now I would like to to create a array like is presented bellow, that consist only one row, and each column is my matrix of 5x5.

I have tried with mat2cell:

MatrixNew= mat2cell(M, 5, 5);

But I have still an error. I dont have clue how to fix it. I am not try to find a ready code but just advice.

How can I accomplish this?

  • So, what have you tried? 3D matrix? Cells? Structures? We're not here to write free code for you. Your image shows a cell, so I guess you tried that. What didn't work about that? – Adriaan Jan 28 '19 at 21:47
  • @Adriaan I have tried C= mat2cell(Matrix, 5,5) but that does not work. I am here not for ready code, just for advice –  Jan 28 '19 at 21:49
  • Problem is: it's still very vague what you want, and what did or did not work. Please [edit] your question to contain a [mcve], with sample inputs **and output** so we know what you want to achieve. Also list what you tried and why those results were unsatisfactory. – Adriaan Jan 28 '19 at 21:50
  • 2
    Hey, I glad that I helped you. But this is not a chat here, to ask some little pieces of questions, and delete them after you get your answer (I suppose there is such a place somewhere...). This is a community that holds constructive topics, usually as Q&A's, but it should reflect a serious effort and have enough importance to the whole community. This specific question is not necessarily unfit (still can be clearer...), but it shows no effort, like your previous ones, and the whole behave here implies on misunderstand of this site – Adiel Jan 28 '19 at 21:51
  • 1
    Sorry if it can be read as unpleasant tone, this is not the purpose. But you need to help people to help you. Here is a good place to start with- https://stackoverflow.com/help/how-to-ask – Adiel Jan 28 '19 at 21:54
  • @Adiel - okey, now i understand, i am very sorry - I reedit the question. –  Jan 28 '19 at 22:02
  • 1
    @Adriaan I have change it, if it's still not enought or its against the stackoverflow I will delete it, or try more to solve it on my own, and put here an answer, but I spend actually a lot of time. I think I am just too stupid for this. –  Jan 28 '19 at 22:03
  • It's fine now, thanks. I don't have MATLAB here to test, but either `mat2cell(M,[5,5])` should work, or `M=reshape(M,5*563,[]); mat2cell(M,[5,5]` I guess. Do note that [`i` and `j` are the imaginary unit in MATLAB](https://stackoverflow.com/q/14790740/5211833), so it's often advised not to use them as variable names. – Adriaan Jan 28 '19 at 22:23
  • @Adriaan - thats the problem, I have tried to use it and that does not work. M=reshape(M,5*563,[]); mat2cell(M,[5,5]) Error using mat2cell (line 89) Input arguments, D1 through D2, must sum to each dimension of the input matrix size, [2815 5]. M=reshape(M,5*563,[]); mat2cell(M,[5,5] M=reshape(M,5*563,[]); mat2cell(M,[5,5] –  Jan 28 '19 at 22:34
  • "But I have still an error." What is this error that you get? Please clarify what the problem is! – Cris Luengo Jan 28 '19 at 23:02
  • @CrisLuengo Error using mat2cell (line 89) Input arguments, D1 through D2, must sum to each dimension of the input matrix size, [2815 5]. –  Jan 28 '19 at 23:05
  • 1
    But `M` is 5x5x563, not 2815x9, isn't it? – Cris Luengo Jan 28 '19 at 23:15
  • @CrisLuengo yes, but after a resize that what propose Adriaan it has change –  Jan 29 '19 at 09:01
  • I’m going off of what you wrote in the question. In the question you compute `M`, then call `mat2cell`, then you get an error. Please [edit] your question to specify what that error is. Why is it not good enough what you propose to do in the question? If your question has changed due to comments here, update your question. You don’t have answers yet, it is fine to change it. – Cris Luengo Jan 29 '19 at 14:42

1 Answers1

0

I think reshape should do the job for you. For example:

x=reshape(M,[1 5*5*563]);

or you can use other variations of the reshape function by playing around with it.

Mostafa Ayaz
  • 480
  • 1
  • 7
  • 16