Run vs. Run and Advance?

11 次查看(过去 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