0

I have the following Matlab code snippet that I'm having to translate to VBScript. However, I'm not understanding why the last line is even necessary.

clear i
for i = 1:numb_days
    doy(i) = floor(dt_daily(i) - datenum(2012,12,31,0,0,0));
end
doy = doy';

Looking over the rest of the code, this happens in a lot of other places where there are single dimension arrays (?) being transposed in place. I'm a newbie when it comes to both these languages, as well as posting a question on Stack, as I'm a sleuth when it comes to finding answers, just not in this case. Thanks in advance.

4
  • 1
    Probably to avoid Matrix dimensions must agree errors. Try [1 2] - [1; 2]. Commented Jul 17, 2013 at 21:38
  • 1
    I think you're right. Apparently, MATLAB treats single dimension arrays as matrices? Which means that the array can be vertical or horizontal, thus necessitating a transpose. Thanks for your insight Commented Jul 17, 2013 at 21:52
  • 1
    Exactly @javon27. The arrays in Matlab are for a lot more than just storing data. Think math. Matlab does stand for "Matrix Labratory" after all. For, example [1 2]'*[1 2], [1 2]*[1 2]' and [1 2].*[1 2] are all different. Commented Jul 17, 2013 at 23:01
  • Thanks. I'm having to translate all this Matlab code, and don't have access to Matlab itself. So, I finally decided to ask on here. Commented Jul 18, 2013 at 17:03

1 Answer 1

1

All "arrays" in MATLAB have at least two dimensions, and can be treated as having any number of dimensions you wish. The transpose operator here is converting between a row (size [1 N] array) and a column (size [N 1] array). This can be significant when it comes to either concatenating the arrays, or performing other operations.

Conceptually, the dimension vector of a MATLAB array has as many trailing 1s as is required to perform an operation. This means that you can index any MATLAB array with any number of subscripts, providing you don't exceed the bounds, like so:

x = magic(4); % 4-by-4 square matrix
x(2,3,1,1,1) % pick an element

One final note: the ' operator is the complex-conjugate transpose CTRANSPOSE. The .' operator is the ordinary TRANSPOSE operator.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.