sir i have written this program i want to know that how can i call the function in the loop... clc; clear all; B=imread('bulb.jpg');
A=imresize(B,[128 128]);
[a b]=size(A);
c=8; d=8; l=0;
for i=1:c:a-7 for j=1:d:b-7
C = A((i:i+7) ,( j:j+7));
eval(['out_' num2str(l) '=C'])
l=l+1;
DCT= dct2(C)
quant = [
16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99
];
quantCoef = round(DCT ./ quant)
end
end
function output=rle2(Input);
L=length(Input); j=1; k=1; i=1; while i<2*L comp=1; for j=j:L if j==L break end; if Input(j)==Input(j+1) comp=comp+1; else break end; end; Output(k+1)=comp; Output(k)=Input(j); if j==L && Input(j-1)==Input(j) break end; i=i+1; k=k+2; j=j+1; if j==L if mod(L,2)==0 Output(k+1)=1; Output(k)=Input(j); else Output(k+1)=1; Output(k)=Input(j); end; break end; end;

 採用された回答

Mischa Kim
Mischa Kim 2014 年 3 月 21 日
編集済み: Mischa Kim 2014 年 3 月 21 日

0 投票

Jitesh, I assume you are referring to the function rle2? If so, turn the preceding script into a function (I called it mymain) and simply call the function with the appropriate input arguments. The m-file should be named like the main function, in this case mymain.m.
function mymain()
...
for i=1:c:a-7
...
out = rle2(in); % in needs to be assigned at this point
...
end
end
function output = rle2(Input)
...
output = ... % return value of the function
end

5 件のコメント

Jitesh Bhanushali
Jitesh Bhanushali 2014 年 3 月 22 日
sir i have wrote as
function mymain() clc; clear all;
B=imread('bulb.jpg');
A=imresize(B,[128 128]);
[a b]=size(A);
c=8; d=8; l=0;
for i=1:c:a-7 for j=1:d:b-7
C = A((i:i+7) ,( j:j+7));
eval(['out_' num2str(l) '=C'])
l=l+1;
DCT = dct2(C)
quant = [
16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99
];
quantCoef = round(DCT ./ quant) out=rle2(quantCoef); end end
function output=rle2(Input)
L=length(Input); j=1; k=1; i=1; while i<2*L comp=1; for j=j:L if j==L break end; if Input(j)==Input(j+1) comp=comp+1; else break end; end; Output(k+1)=comp; Output(k)=Input(j); if j==L && Input(j-1)==Input(j) break end; i=i+1; k=k+2; j=j+1; if j==L if mod(L,2)==0 Output(k+1)=1; Output(k)=Input(j); else Output(k+1)=1; Output(k)=Input(j); end; break end; end; end; end;
but it gives error as
This statement is not inside any function. (It follows the END that terminates the definition of the function "mymain".)
what should i do..please help
Mischa Kim
Mischa Kim 2014 年 3 月 22 日
編集済み: Mischa Kim 2014 年 3 月 22 日
What is the exact error msg? Also, please format the code or attach it to your question (see paper clip icon).
Jitesh Bhanushali
Jitesh Bhanushali 2014 年 3 月 22 日
the error is about the the "end" of the function
Mischa Kim
Mischa Kim 2014 年 3 月 22 日
編集済み: Mischa Kim 2014 年 3 月 22 日
A couple of things:
  • Remove all the semi-colons after the end statements.
  • Remove the very last end statement and add one right before the function definition for rle2.
  • Change output to Output (variable names are case-sensitive) in the function definition for rle2.
See attachment below.
Jitesh Bhanushali
Jitesh Bhanushali 2014 年 3 月 24 日
sir , i tried to run this mymain.m but i got RLE of the only first column of the matrix..can i get whole matrix using IRLE and this RLE output??

サインインしてコメントする。

その他の回答 (3 件)

Jitesh Bhanushali
Jitesh Bhanushali 2014 年 3 月 22 日

0 投票

how to end the function//
Jitesh Bhanushali
Jitesh Bhanushali 2014 年 3 月 22 日

0 投票

i got error as
??? Attempt to add "out_0" to a static workspace. See MATLAB Programming, Restrictions on Assigning to Variables for details.
Error in ==> mymain at 20 eval(['out_' num2str(l) '=C'])
Jitesh Bhanushali
Jitesh Bhanushali 2014 年 3 月 22 日

0 投票

file attached

1 件のコメント

Mischa Kim
Mischa Kim 2014 年 3 月 22 日
I added the final comments and a working m-file above with my previous comment.
Please add follow-up questions and comments as comments, not answers.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Develop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by