How to save .mat file in a function?
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello, i have a function, i wanna save the result to .mat file. i try to execute save example.mat result , but i doesn't work. what should i do? this is my function
function result=plus(images)
[rmax, cmax] = size(images);
for row = 1:rmax;
for col = 1:cmax;
if images(row,col)== 1
a=14;
b=2;
result=a+b
end
end
end
save example.mat result
I purposely don't add a semicolon in the "result = a + b", in order to show the row and column which produces number 16
thanks in advance
댓글 수: 0
답변 (2개)
Carlos
2013년 4월 3일
Your last line should be
save('example.mat', 'result');
댓글 수: 3
Matt Kindig
2013년 4월 3일
It's unclear what you expect 'result' to be. You define 'result' to be a+b, which will always give you 16 since you have defined a=14 and b=2. In what sense does your code not work?
Walter Roberson
2013년 4월 3일
You are writing over all of the variable "result" on every iteration of the loop. Try
result(row, col) = a+b;
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!