I am keep on getting this error in my matlab code when i try to execute this code.

7 views (last 30 days)
Error in thermdata (line 2)
cd 'C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic arm\Thermdynamics Parsing NASA';
This is the error mentioned above which i am keep on getting. I will copy and paste all the text in my command window. One of my frind told me it could be related to the incorrect file as well.
Command window.
thermdata
Current directory: /MATLAB Drive
Contents of the directory:
curvefittingg.m Editor_dusyp f.m odecylce.m quadratic.m unn.m
curvefitting.m Editor_mxxlx fprintf.m ode_func.m quiz3.m untitled.m
data.m Editor_pnwvg hhh.m pp.m thermdata.m Welcome.mlx
Editor Editor_wacxv hyper.m Published totalcost.m
Error using thermdata
Could not open the file: thermo.dat
thermdata
Warning: Function fprintf has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
Error using cd
Unable to change current folder to '/MATLAB Drive/C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic
arm\Thermdynamics Parsing NASA' (Name is nonexistent or not a folder).
Error in thermdata (line 2)
cd('C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic arm\Thermdynamics Parsing NASA');
thermdata
Warning: Function fprintf has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
Error using cd
Unable to change current folder to '/MATLAB Drive/C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic
arm\Thermdynamics Parsing NASA\thermodata.m' (Name is nonexistent or not a folder).
Error in thermdata (line 2)
cd 'C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic arm\Thermdynamics Parsing NASA\thermodata.m'
Warning: Function fprintf has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
thermdata
Warning: Function fprintf has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
Error using cd
Unable to change current folder to '/MATLAB Drive/C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic
arm\Thermdynamics Parsing NASA' (Name is nonexistent or not a folder).
Error in thermdata (line 2)
cd 'C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic arm\Thermdynamics Parsing NASA';
thermdata
Error using cd
Unable to change current folder to '/MATLAB Drive/C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic
arm\Thermdynamics Parsing NASA' (Name is nonexistent or not a folder).
Error in thermdata (line 2)
cd 'C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic arm\Thermdynamics Parsing NASA';
Warning: Function fprintf has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
thermdata
Warning: Function fprintf has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
Error using cd
Unable to change current folder to '/MATLAB Drive/C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic
arm\Thermdynamics Parsing NASA' (Name is nonexistent or not a folder).
Error in thermdata (line 2)
cd 'C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic arm\Thermdynamics Parsing NASA';
Warning: Function fprintf has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
thermdata
Warning: Function fprintf has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
Error using cd
Too many input arguments.
Error in thermdata (line 2)
cd C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic arm\Thermdynamics Parsing NASA
Warning: Function fprintf has the same name as a MATLAB built-in. We suggest you rename the function to avoid a potential name conflict.
thermdata
Error using cd
Unable to change current folder to '/MATLAB Drive/C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic
arm\Thermdynamics Parsing NASA' (Name is nonexistent or not a folder).
Error in thermdata (line 2)
cd 'C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic arm\Thermdynamics Parsing NASA';
thermdata
Error using cd
Unable to change current folder to '/MATLAB Drive/C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic
arm\Thermdynamics Parsing NASA' (Name is nonexistent or not a folder).
Error in thermdata (line 2)
cd 'C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic arm\Thermdynamics Parsing NASA';
thermdata
Error using cd
Unable to change current folder to '/MATLAB Drive/C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic
arm\Thermdynamics Parsing NASA' (Name is nonexistent or not a folder).
Error in thermdata (line 2)
cd 'C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic arm\Thermdynamics Parsing NASA';

Answers (1)

Steven Lord
Steven Lord on 28 Feb 2024
Why have you written your own fprintf.m file? That means you won't be able to call the fprintf function that is part of MATLAB and is the reason for some of the warning messages. I advise you to rename or remove your fprintf.m.
The relevant message appears to be:
Error using cd
Unable to change current folder to '/MATLAB Drive/C:\Users\joelg\OneDrive\Desktop\Advanced technologies in mechanical engineering\DevelopingNumericSortingAlgorithm\CodeForRpbotic
arm\Thermdynamics Parsing NASA' (Name is nonexistent or not a folder).
Are you using MATLAB Online? If so I'm fairly sure it won't be able to access files in your OneDrive and certainly wouldn't be able to do so using a Windows path. I think you're going to need to upload those files to MATLAB Drive or make them available via MATLAB Drive Connector.
But at a quick glance, are you sure the folder path is correct? Should "CodeForRpbotic arm" be "CodeForRobotic arm" and should "Thermdynamics Parsing NASA" be "Thermodynamics Parsing NASA"?
  2 Comments
joel george
joel george on 28 Feb 2024
clear all
close all
clc
% Define the file path
file_path = 'thermo.date';
% Attempt to open the file for reading
try
f1 = fopen(file_path, 'r');
% Check if file opening was successful
if f1 == -1
error('Could not open the file.');
end
% Reading the comment lines
for i = 1:5
fgetl(f1);
end
% Extracting all species data
for i = 1:53
% Extracting name of gas species
A = fgetl(f1);
z = findstr(A, ' ');
species_name = A(1:z(1)-1);
% Extracting local temperatures of gas species
t1 = str2double(A(z(1):z(2)));
t2 = str2double(A(z(2):z(3)));
t3 = str2double(A(z(3):end));
% Extracting co-efficient of gas species
B = fgetl(f1);
a_values = sscanf(B, '%f');
a1 = a_values(1);
a2 = a_values(2);
a3 = a_values(3);
a4 = a_values(4);
a5 = a_values(5);
C = fgetl(f1);
a_values = sscanf(C, '%f');
a6 = a_values(1);
a7 = a_values(2);
a8 = a_values(3);
a9 = a_values(4);
a10 = a_values(5);
D = fgetl(f1);
a_values = sscanf(D, '%f');
a11 = a_values(1);
a12 = a_values(2);
a13 = a_values(3);
a14 = a_values(4);
% Creating the range of low and high values of local temperatures
T = linspace(t1, t3, 1000);
R = 8.314; % Universal gas constant in J/mol.K
% Calculation for Specific heat, Enthalpy and Entropy
for j = 1:length(T)
if T(j) > t2
Cp(j) = (a1 + a2*T(j) + a3*T(j)^2 + a4*T(j)^3 + a5*T(j)^4)*R;
H(j) = (a1 + (a2*T(j))/2 + (a3*T(j)^2)/3 + (a4*T(j)^3)/4 + (a5*T(j)^4)/5 + (a6/T(j)))*R*T(j);
S(j) = a1*log(T(j)) + a2*T(j) + (a3*T(j)^2)/2 + (a4*T(j)^3)/3 + (a5*T(j)^4)/4 + a7;
else
Cp(j) = (a8 + a9*T(j) + a10*T(j)^2 + a11*T(j)^3 + a12*T(j)^4)*R;
H(j) = (a8 + (a9*T(j))/2 + (a10*T(j)^2)/3 + (a11*T(j)^3)/4 + (a12*T(j)^4)/5 + (a13/T(j)))*R*T(j);
S(j) = a8*log(T(j)) + a9*T(j) + (a10*T(j)^2)/2 + (a11*T(j)^3)/3 + (a12*T(j)^4)/4 + a14;
end
end
% Molecular weight calculation
elements = ['H', 'C', 'O', 'N', 'A', 'S'];
atomic_weight = [1.0079 12.0107 15.999 14.0067 39.948 32.065];
mol_mass = 0;
for l = 1:length(species_name)
for m = 1:length(atomic_weight)
if strcmp(species_name(l), elements(m))
mol_mass = mol_mass + atomic_weight(m);
position = m;
end
end
n = str2double(species_name(l));
if n > 1
mol_mass = mol_mass + atomic_weight(position)*(n-1);
end
end
% Printing the molecular weight of the gas species in the command window
fprintf('Molecular Weight of %s is %f u\n', species_name, mol_mass);
% Creating a folder to save the plots
mkdir(species_name);
cd(species_name);
% Plotting specific heat vs temperature
figure(1)
plot(T, Cp, 'color', 'b', 'linewidth', 2)
xlabel('Temperature (K)')
ylabel('Specific Heat (J/K Kg)')
title({'Specific Heat vs Temperature', ['Species name = ', species_name, ' & Molecular weight = ', num2str(mol_mass)]});
saveas(gcf, 'Cp_vs_Temp.png')
% Plotting enthalpy vs temperature
figure(2)
plot(T, H, 'color', 'r', 'linewidth', 2)
xlabel('Temperature (K)')
ylabel('Enthalpy (J/K)')
title({'Enthalpy vs Temperature', ['Species name = ', species_name, ' & Molecular weight = ', num2str(mol_mass)]});
saveas(gcf, 'Enthalpy_vs_Temp.png')
% Plotting entropy vs temperature
figure(3)
plot(T, S, 'color', 'g', 'linewidth', 2)
xlabel('Temperature (K)')
ylabel('Entropy (J/K)')
title({'Entropy vs Temperature', ['Species name = ', species_name, ' & Molecular weight = ', num2str(mol_mass)]});
saveas(gcf, 'Entropy_vs_Temp.png')
% To change the current directory to the main folder
cd('..');
end
% Close the file
fclose(f1);
catch ME
% Error handling for various reasons file cannot be opened
switch ME.identifier
case 'MATLAB:fopen:FileNotFound'
disp('File not found. Please check the file path.');
case 'MATLAB:fopen:PermissionDenied'
disp('Permission denied. MATLAB does not have the necessary permissions to read the file.');
case 'MATLAB:fopen:InvalidPermission'
disp('Invalid file permissions. Please check file permissions.');
case 'MATLAB:fopen:InvalidFid'
disp('Invalid file identifier. Use fopen to generate a valid file identifier.');
otherwise
disp('An unknown error occurred while opening the file.');
disp(ME.message);
end
end
An unknown error occurred while opening the file.
Could not open the file.
Walter Roberson
Walter Roberson on 28 Feb 2024
[f1, msg] = fopen(file_path, 'r');
% Check if file opening was successful
if f1 == -1
error('Could not open the file because: %s', msg);
end

Sign in to comment.

Categories

Find more on Thermal Analysis in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!