Run vs. Run and Advance?
11 次查看(过去 30 天)
显示 更早的评论
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
2019-7-3
That is generally considered the safer way to load variables in from files, then just access them from the struct.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!