How to save variables from function output to workspace?

조회 수: 4 (최근 30일)
Simone Frauenfelder
Simone Frauenfelder 2017년 5월 2일
댓글: Stephen23 2017년 5월 3일
function [ A, B] = GetText(filename)
fid = fopen(filename,'r');
x = textscan(fid,'%n%s','headerlines',1);
fclose(fid);
A = x(:,1);
B = x(:,2);
B{1}
A{1}
end
When I run this function the output is ans = "the data in the 1st column" and ans = "data in the 2nd column" and ans = [108x1 double] but the variables 'A' and 'B' are not saved to the workspace. How to I fix the function so the answers are defined as A and B and the variables are saved to the workspace?
  댓글 수: 1
Stephen23
Stephen23 2017년 5월 3일
@Simone Frauenfelder: today I formatted your code correctly for you. Next time you can do it yourself: select the code text, then click the {} Code button above the textbox.

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

답변 (1개)

Alessandro
Alessandro 2017년 5월 2일
편집: Alessandro 2017년 5월 2일
You are probably calling the function in a wrong way from your script/command line.
[A,B] = GetText(filename);
will save both variables A and B in the workspace.

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by