Run vs. Run and Advance?
Ältere Kommentare anzeigen
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 Kommentare
Geoff Hayes
am 2 Jul. 2019
Iris - please copy and paste the full error message to your question. It may be helpful to post some or all of your code.
Adam
am 3 Jul. 2019
What is Version_30x2E0 supposed to be? A variable or a function? Where is it defined?
IE
am 3 Jul. 2019
IE
am 3 Jul. 2019
Adam
am 3 Jul. 2019
That is generally considered the safer way to load variables in from files, then just access them from the struct.
IE
am 3 Jul. 2019
Antworten (0)
Kategorien
Mehr zu Workspace Variables and MAT Files finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!