1
votes

I have to translate in MATLAB this Fortran statement (variable initialization):

data k/350*'  '/

where k was declared like

character*2 k(31,12)

I have read that * is equal to comma, that is to say k will be an array of two elements, 350 and an empty cell?

What should I write in MATLAB? This k=['350',''];?

1
If you want to enter 350 as a number then k={350, [] }. If you want to enter 350 as a string then k={'350',[]} mathworks.com/help/matlab/getting-started-with-matlab.html - Sardar Usama
It is declared as "character*2 k(31,12)". - scana

1 Answers

0
votes

In a data statement * is not the same as ,: , is a separator, but * is a repeat count specifier.

The example of the question

character*2 k(31,12)
data k/350*'  '/

has the initialization value equal to 700 blanks and k is a rank-2 array (of shape [31,12]) of length-2 characters.

Ideally, the size of k would be identical to the size of the initialization value expression but there is a difference: 744, and 700. Let's just assume that the intention is that each element of the array k has value ' ' (ie., all blanks).

As to the best way of doing that in MATLAB, I'm no expert. But if necessary I'll add a way (or someone else can). Hopefully the explanation of what the Fortan code is (intended to do/) doing is sufficient.