Jpeg file as funcion input

조회 수: 2 (최근 30일)
Matteo Breda
Matteo Breda 2015년 5월 20일
댓글: Matteo Breda 2015년 5월 20일
I'm working on a funtion that is processing some info taken from Jpeg photos; I need to have a Jpeg file as input but I'm not able to fix the code; when I wrote the jpeg file path as input,
function [ output ] = funcion_name( 'C:\path\photo.jpg' )
matlab is giving me this error ''Unexpected MATLAB expression.''

채택된 답변

Guillaume
Guillaume 2015년 5월 20일
A function has arguments as inputs, and it is up to the function to interpret these arguments as appropriate. Thus, you would declare your function as:
function output = function_name(jpegfile)
%check that file is jpeg:
try
info = imfinfo(jpegfile);
catch
error('File not found or not an image');
end
assert(strcmp(info.Format, 'jpg'), 'Image is not jpeg');
%do something with file...
And you specify the file in the call to the function
result = function_name('C:\path\photo.jpg');
Unless, you meant to have the file a constant in the function, in which case:
function output = function_name()
jpegfile = 'C:\path\photo.jpg';
%do something with jpegfile
  댓글 수: 1
Matteo Breda
Matteo Breda 2015년 5월 20일
Thanks for the help

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by