Error using fgets Invalid file identifier. Use fopen to generate a valid file identifier.

4 views (last 30 days)
CODE
clear all; close all; clc
addpath('apm')
s = 'http://byu.apmonitor.com';
a = 'data_regression';
apm(s,a,'clear all');
apm_load(s,a,'model.apm');
csv_load(s,a,'data.csv');
apm_info(s,a,'FV','a');
apm_info(s,a,'FV','b');
apm_info(s,a,'FV','c');
apm_option(s,a,'a.status','1');
apm_option(s,a,'b.status','1');
apm_option(s,a,'c.status','1');
apm_option(s,a,'nlc.imode',2);
output = apm(s,a,'solve');
disp(output)
ERROR
Error using fgets
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in apm_load (line 21)
aline = fgets(fid);
Error in Regression (line 10)
apm_load(s,a,'model.apm');

Answers (1)

Voss
Voss on 4 Jan 2023
Specify the file names as absolute or relative path names. That is, instead of specifying just the file name "model.apm", if "model.apm" is located in the "apm" directory, which is in the current working directory, you could say:
model_file_name = fullfile('.','apm','model.apm');
apm_load(s,a,model_file_name);
That's a relative path (relative to the current working directory). You could also use an absolute path, e.g.:
model_file_name = 'C:\Users\banjo\apm\model.apm'; % or wherever model.apm is on your computer
apm_load(s,a,model_file_name);
Similarly for other file names you need to specify.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!