필터 지우기
필터 지우기

Error using textscan Invalid file identifier Use fopen to generate a valid file identifier in app designer

조회 수: 3 (최근 30일)
I use a button to upload my "Data.txt" file and another button to calculate and plot it into UIaxes but im having error in "fid=fopen"
properties (Access = public)
selectpath='';
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: UploadButton
function UploadButtonPushed(app, event)
[file,path] = uigetfile('*.txt')
end
% Button pushed function: CalculateButton
function CalculateButtonPushed(app, event)
fid=fopen(Data.txt(app.selectpath));
fclose(fid); %Error using textscan
% Invalid file identifier.
% Use fopen to generate a valid file identifier.
seek=textscan(fid,'%f %f','headerlines',2);
g = cell2mat(seek);
x=g(:,1);
y=g(:,2);
[sortedX, sortIndex] = sort(x);
sortedY = y(sortIndex);
sortedXLimit = sortedX(1:160,:);
sortedYLimit = sortedY(1:160,:);
plot(app.UIAxes,value*peaks) %for the graph
app.UIAxes.YLim = [0 205];
  댓글 수: 5

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

채택된 답변

Tommy
Tommy 2020년 4월 30일
편집: Tommy 2020년 4월 30일
It doesn't seem like your upload button stores anything. It saves the file and path into file and path and then exits, at which point the file and path are lost. This would work:
function UploadButtonPushed(app, event)
[file,path] = uigetfile('*.txt');
if file == 0
% handle case where user clicks cancel
else
app.selectpath = fullfile(path, file);
end
end
And then in your other callback:
function CalculateButtonPushed(app, event)
fid=fopen(app.selectpath);
seek=textscan(fid,'%f %f','headerlines',2);
...
  댓글 수: 10
Tommy
Tommy 2020년 5월 1일
Hmm... I'll assume you want to plot your sorted and trimmed y over your sorted and trimmed x, in which case you should try
plot(app.UIAxes,sortedXLimit,sortedYLimit)
If that's not what you want, could you provide the code which worked for you?

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

추가 답변 (1개)

sydney salvador
sydney salvador 2020년 5월 1일
[sortedX, sortIndex] = sort(x);
sortedY = y(sortIndex);
sortedXLimit = sortedX(1:160,:);
sortedYLimit = sortedY(1:160,:);
plot(app.UIAxes,sortedXLimit,sortedYLimit)
app.UIAxes.YLim = [0 1000];
hold on
findpeaks(sortedYLimit,sortedXLimit,'MinPeakProminence',205,'Annotate','extents')
sir my peaks arent showing on the graph on app designer, it shows in another window in matlab and when i use hold on it does not work

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by