one thing i need to know

2 views (last 30 days)
ar fa
ar fa on 2 Apr 2015
Commented: Star Strider on 3 Apr 2015
hello I am c# programmer. after coding using matlab, I was faced with a problem. I can't convert below c# codes to matlab:
public double[][] Transpose(double[][] M)
{
double[][] R = new double[M[0].Length][];
for (int c = 0; c < M[0].Length; c++)
R[c] = new double[M.Length];
for (int i = 0; i < M.Length; i++)
{
for (int j = 0; j < M[0].Length; j++)
{
R[j][i] = M[i][j];
}
}
return R;
}
Please Help me to convert this code to matlab code and not recommend to use matlab function. Thanks

Accepted Answer

ar fa
ar fa on 3 Apr 2015
Edited: James Tursa on 3 Apr 2015
I find solution for creating dynamic array in matlab:
How to Create it:
x = {zeros(1,30);zeros(1,20);zeros(1,10)};
x{4} = x;
How to Access it:
Write:
x{4}{1}(25) = 5;
Read:
x{4}{1}
Good luck
  2 Comments
Star Strider
Star Strider on 3 Apr 2015
... and that’s the one thing ‘ar fa’ needs to know.
Now, a universal polymath!

Sign in to comment.

More Answers (2)

James Tursa
James Tursa on 2 Apr 2015
Edited: James Tursa on 2 Apr 2015
R = M'
Or if you want to strictly transpose for complex arguments as well,
R = M.'
  3 Comments
Stephen23
Stephen23 on 3 Apr 2015
The second, non-conjugate transpose is the correct answer.

Sign in to comment.


Andrew Newell
Andrew Newell on 2 Apr 2015
For your specific problem, some useful pages are Matrix Indexing in MATLAB, Loop Control Statements and Create Functions in Files. But you seem to be starting from zero knowledge of MATLAB, so you really should start with a tutorial. It wouldn't do you much good if we simply converted your function to MATLAB because you wouldn't know what to do with it.

Tags

Community Treasure Hunt

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

Start Hunting!