필터 지우기
필터 지우기

Exporting matrices from function to cell array

조회 수: 3 (최근 30일)
Mohammed Hammouda
Mohammed Hammouda 2021년 3월 11일
댓글: Stephen23 2021년 3월 12일
Hello all,
So I am trying to process some images. The function reads the image and stores it internally in a variable called avg ( as a matrix). And since this is happening inside the function I can not access tha variable avg.
So I did a little research and found assigin() function. However, I have tried to store these matrices in a cell array that I have opened in the testFunction file, which is not the function file ( I just call the function from this file), but the cell array remains empty.
This is my empty cell array function
CesarelliFlt_img = {};
This is my assignin() function
assignin('base','CesarelliFlt_img',avg);
Yes I know that this will only store the last value since there is no for loop. So I did this
assignin('base',CesarelliFlt_img{k},avg);
This now returns a CesarelliFlt_img cell file with 0X0 .
k is my for loop variable in that the filter function uses to go through the images.
What might seem to be the problem? I feel I am not using assignin right , specially the variable name section.
Thanks in advance.
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2021년 3월 11일
hello
why not simply make the variable avg accessible as one output argument of the function ?
Stephen23
Stephen23 2021년 3월 12일
"And since this is happening inside the function I can not access tha variable avg."
Sure you can: a simple output argument lets you do that, much simpler and more efficient than your approach.

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

답변 (1개)

Jan
Jan 2021년 3월 11일
Use an output argument to provide variables to the caller.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by