Attempted to access TPvhs.data(3); index out of bounds because numel(TPvhs.data)=1.

Hi, I've discovered that this is a common error. I have created a variable that is 1x1 but I'm trying to acces with a different size. I've traied to fix it...but I failed!
Can someone help me?
Thanks!
R='CarbonDioxide';
T=300;
P=100;
%open the input file for writing
fid=fopen('C:\users\alessandro\desktop\input.dat','w');
%write the inputs to the file
fprintf(fid,'''%s'' %f %f',R,T,P);
%close the file
fclose(fid);
%run the macro file
system('C:\EES32\EES.exe C:\users\alessandro\desktop\Macro.emf');
%import results from the file
TPvhs=importdata('C:\users\alessandro\desktop\output.dat');
%assign the results to outputs
v=TPvhs.data(3);
h=TPvhs.data(4);
s=TPvhs.data(5);

 Accepted Answer

Maybe you should do
v=TPvhs(3).data;
h=TPvhs(4).data;
s=TPvhs(5).data;

4 Comments

Thanks for the fast response...but doesn't work with your suggestion
I'm following this guide, without succes:
Executing an EES Macro File from MATLAB EES can be started and directed to run a predefined macro file from most programs. This capabililty allows other programs to communicate with EES and direct its execution. To illustrate this capability, we will develop a MATLAB function that returns the specific volume, specific enthalpy, and specific entropy given the fluid, temperature, and pressure.
The MATLAB function is called EESProperty; the header is given below:
function[v, h, s] = EESProperty(R, T, P)
%[v,h,s]=EESProperty(R,T,P)
% Inputs
% R = an EES recognized fluid
% T = temperature (C)
% P = pressure (kPa)
% Outputs
% v = specific volume (m^3/kg)
% h = specific enthalpy (J/kg)
% s = specific entropy (J/kg-K)
end
The file C:\Temp\Input.dat is opened using the fopen command in MATLAB. Note the 'w' flag indicates that the file is available to write to and any existing contents are flushed. The fprintf command is used to write the inputs R, T, and P to the file. Notice the formatting required to put single quotes around the string R so that it is read appropriately as a string in EES. The file is closed using the fclose command.
fid=fopen('C:\Temp\Input.dat','w'); %open the input file for writing
fprintf(fid,'''%s'' %f %f',R,T,P); %write the inputs to the file
fclose(fid); %close the file
The system command in MATLAB executes a command in the operating system as if it were entered into the Run Window. We will use the system command to open EES with the macro file name as an input parameter.
system('C:\EES_CAE\EES.exe C:\Temp\aMacro.emf'); %run the macro file
EES will open and automatically execute the commands in the macro C:\Temp\aMacro.emf. A listing of aMacro.emf follows.
Open 'C:\Temp\TestMacro.ees'
Units SI C kPa J Mass
Import 'C:\Temp\Input.dat' R$ T P
Solve
Export 'C:\Temp\Output.dat' R$ T P v h s
Quit
The EES file that is opened in the macro file contains the following EES code.
v=volume(R$,T=T,P=P)
h=enthalpy(R$, T=T,P=P)
s=entropy(R$, T=T,P=P)
Executing the system command in MATLAB causes EES to open the file C:\Temp\Input.dat and assign the contents to the variables R$, T, and P in the EES file. The file is solved and the properties v, h, and s are written to the file C:\Temp\Output.dat. Finally, EES is closed. All that remains is to open the file C:\Temp\Output.dat and assign the values to the output parameters v, h, and s in the MATLAB function EESProperty. This is done using the importdata command in MATLAB.
TPvhs=importdata('C:\Temp\Output.dat'); %import results from the file
v=TPvhs.data(3); %assign the results to outputs
h=TPvhs.data(4);
s=TPvhs.data(5);
The MATLAB function EESProperty can now be run like any other MATLAB function providing access to EES' internal property routines. To calculate the properties of R134a at 50ºC and 200 kPa, enter the following lines in the MATLAB Command Window:
>> R='R134a';T=50;P=200;
>> [v,h,s]=EESProperty(R,T,P)
v =
0.1277
h =
2.9670e+005
s =
1.1164e+003
TPvhs
store 5 variable. 2 inputs:
  1. the temperature, T
  2. the pressure, P;
and 3 outputs:
  1. volume,v
  2. entalpy,h
  3. entropy,s

Sign in to comment.

More Answers (0)

Categories

Find more on Programming 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!