Run vs. Run and Advance?

조회 수: 5 (최근 30일)
IE
IE 2019년 7월 1일
댓글: IE 2019년 7월 3일
When I run my function, it doesn't work, and results in the error "Undefined function or variable". When divide my code into sections and I Run and Advance through the sections, it works fine. This has persisted after restarting MATLAB. Why could this be the case?
Edit: error message and code below. It is kind of clunky, I'm definitely not an expert on MATLAB or programming in general . It takes in a comma delimited file, which it converts into a character array because it isn't a single matrix so much as a 22x1 stacked on a 446x845, and this code converts it into a table by lopping of the unnecessary top portion and converting it into a bunch of different things. It inexplicably works if i just take all the function code and paste it into my other function, which does some data analysis, but I'd prefer to fix the function so I can use it in other projects.
Error:
Undefined function or variable 'Version_30x2E0'.
Error in TdfToTab (line 18)
pHold=Version_30x2E0;
Code:
function [outTable]=TdfToTab(dest)
%A function to convert comma delimited norm and other files into usable
%data for matlab. Produces temporary text files newF,pHold in current
%directory
%% Opening file
fileID=fopen('pHold.txt','w');
fileID2=fopen('newF.txt','w');
%get file
tdfread(dest,'comma');
pause(2);
%% Conversion
pHold=Version_30x2E0;
% delete first 22 lines
pHold([1:22],:)=[];
%save as new text file
char_array = pHold;
for jj = 1:125
fprintf(fileID,'%s\n', length(char_array(jj,:)),char_array(jj,:) );
end
fileID=fopen('pHold.txt','r');
fprintf('\n');
newF=fscanf(fileID,'%c');
newF(regexp(newF,char(26)))=[];
%now save that text file
fprintf(fileID2,newF);
%reopen as table
outTable=readtable('newF.txt');
end
  댓글 수: 6
Adam
Adam 2019년 7월 3일
That is generally considered the safer way to load variables in from files, then just access them from the struct.
IE
IE 2019년 7월 3일
That fixed it. Thanks.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by