Filter löschen
Filter löschen

Convert this C program into a Matlab program.

1 Ansicht (letzte 30 Tage)
Virajan Verma
Virajan Verma am 16 Okt. 2018
Kommentiert: Walter Roberson am 18 Okt. 2018
ex[1]=lx/J %%first i term in ex matrix
ex[2]=mx/J %%second j term in ex matrix
ex[3]=nx/J %%third k term in ex matrix
for (i=0;i<9;i++)
for (j=0;i<27;j++)
N_matrix[i,j]=0;
end
for (i=0;i<9;i++)
N_matrix(0,i)=N[i%3]*ex[i/3];
end
  4 Kommentare
Jan
Jan am 16 Okt. 2018
Bearbeitet: Jan am 16 Okt. 2018
@Virajan Verma: You are not a newbie in this forum. I've formatted the code for your today, but please mark the code with the mouse and press the "{} Code" button by your own in the future. Thanks.
This is not C code, because there is no "end" in C. What is N? Are you sure that you want to insert values in the first row, not column?
Guillaume
Guillaume am 16 Okt. 2018
N_matrix(0,i) is also not correct C syntax. The brackets should be square.
And as Jan pointed out, it should probably be:
N_matrix[i,0]

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 16 Okt. 2018
ex = [lx; mx; nx] / J;
N = rand(3, 1); % ???
N_matrix = zeros(9, 27);
N_matrix(1, 1:9) = repmat(N, 3, 1) .* repelem(ex, 3, 1)
  4 Kommentare
Virajan Verma
Virajan Verma am 18 Okt. 2018
@Jan
Walter Roberson
Walter Roberson am 18 Okt. 2018
That code creates a row vector for N, not a column vector. Try N(1,1), N(2,1), N(3,1) as the destinations

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by