フィルターのクリア

Translating MATLAB code into C

2 ビュー (過去 30 日間)
Hiroshi Nakamura
Hiroshi Nakamura 2015 年 3 月 1 日
編集済み: Hiroshi Nakamura 2015 年 3 月 1 日
Hello guys, I was just wondering if anyone can help translate my code into C as I don't have MATLAB Coder . I am more familiar with MATLAB's array indexing and I believe that C's array indexing is a little too complicated for a beginner like me. I'd appreciate it if you could walk me through the steps..
I am currently stuck at these two lines and I believe C won't allow me to do array indexing the same way MATLAB does:-
b = a(x:x+1, y:y+1);
a(x:x+1, y:y+1) = b;
Here is my entire code :-
a = [1 2 3 4; 2 3 4 5; 3 4 5 6; 4 5 6 7];
c = dctmtx(2);
q_mtx = [16 11; 12 12];
for x = 1:2:M
for y = 1:2:N
b = a(x:x+1, y:y+1); %<----HOW DO I DO THIS IN C???
b = c*b*c';
b = b./q_mtx ;
a(x:x+1, y:y+1) = b;
end
end

採用された回答

Walter Roberson
Walter Roberson 2015 年 3 月 1 日
for (xoff = 0, xoff <= 1, xoff++)
for (yoff = 0, yoff <= 1, yoff++)
b[yoff][xoff] = a[y+yoff][x+xoff];
That is, you use a loop. Unless you want to start into memcpy().
Notice that I reversed the order of the indices. C arrays are row-major instead of column-major.

その他の回答 (1 件)

Hiroshi Nakamura
Hiroshi Nakamura 2015 年 3 月 1 日
編集済み: Hiroshi Nakamura 2015 年 3 月 1 日
Thank you so much Walter! I really appreciate it! One more question. What are y and x again in you loop? Also if I were to do it using memcopy, how would I go about doing it? Thanks again!
for (xoff = 0, xoff <= 1, xoff++)
for (yoff = 0, yoff <= 1, yoff++)
b[yoff][xoff] = a[y+yoff][x+xoff];

カテゴリ

Help Center および File ExchangeTest Model Components についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by