Effacer les filtres
Effacer les filtres

Run vs. Run and Advance?

6 vues (au cours des 30 derniers jours)
IE
IE le 1 Juil 2019
Commenté : IE le 3 Juil 2019
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 commentaires
Adam
Adam le 3 Juil 2019
That is generally considered the safer way to load variables in from files, then just access them from the struct.
IE
IE le 3 Juil 2019
That fixed it. Thanks.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by