exporting HYSYS stripchart using MATLAB

12 ビュー (過去 30 日間)
Jun Jie
Jun Jie 2024 年 7 月 3 日
編集済み: Walter Roberson 2024 年 7 月 4 日
I want to export HYSYS stripchart using MATLAB code

回答 (7 件)

Umar
Umar 2024 年 7 月 3 日
編集済み: Walter Roberson 2024 年 7 月 4 日
Hi Jun,
You asked about exporting HYSYS stripchart using MATLAB code.
I can definitely help you out to accomplish your goal. First, establish a connection to the running HYSYS simulation. Then, access the stripchart data and export it to a file format of your choice using MATLAB's file writing functions. Let me demonstrate by providing a simple example to help you get started.
% Connect to the running HYSYS simulation
hysys = actxserver('HYSYS.Application');
% Access the stripchart data
stripchart = hysys.ActiveDocument.StripChart;
% Export the stripchart data to a CSV file
data = stripchart.Data;
csvwrite('exported_stripchart_data.csv', data);
% Close the HYSYS application
hysys.Quit;
Please remember to adjust the code according to your specific requirements and the structure of your HYSYS simulation. This approach will allow you to automate the export process and analyze the data further using MATLAB.
Hope this will help resolve your problem.
  1 件のコメント
Jun Jie
Jun Jie 2024 年 7 月 3 日
Hi umar, thank you for your answer...
I tried the above code previously and it did not work... it says no method with matching signature found for class.
may I trouble you further to explain a bit more?

サインインしてコメントする。


Umar
Umar 2024 年 7 月 3 日
編集済み: Walter Roberson 2024 年 7 月 4 日
Hi Jun,
I tried the above code previously and it did not work... it says no method with matching signature found for class. may I trouble you further to explain a bit more?
I figured out why it caused the error because the code was trying to access data in a way that is not supported by the HYSYS API. One way to achieve this is by iterating over the data points in the stripchart and then writing them to a CSV file. So, establish a connection to a running HYSYS simulation using the actxserver function. Access the stripchart data from the active document in the HYSYS simulation. Then, retrieve the data points from the stripchart and stores them in a matrix. Export the stripchart data stored in the matrix to a CSV file named exported_stripchart_data.csv. Finally, close the HYSYS application using the Quit method.
% Connect to the running HYSYS simulation
hysys = actxserver('HYSYS.Application');
% Access the stripchart data
stripchart = hysys.ActiveDocument.StripChart;
% Get the number of data points in the stripchart
numPoints = stripchart.DataPoints.Count;
% Initialize a matrix to store the data
data = zeros(numPoints, 1);
% Retrieve data points from the stripchart
for i = 1:numPoints
data(i) = stripchart.DataPoints.Item(i).Value;
end
% Export the stripchart data to a CSV file
csvwrite('exported_stripchart_data.csv', data);
% Close the HYSYS application
hysys.Quit;
Hopefully, this time it should work.
  2 件のコメント
Jun Jie
Jun Jie 2024 年 7 月 3 日
ok i will try and update u thank you! :)
Jun Jie
Jun Jie 2024 年 7 月 3 日
>> % Access the stripchart data
stripchart = hysys.ActiveDocument.StripChart;
Unrecognized method, property, or field 'StripChart' for class
'Interface.4FCE6E77_A334_46E3_9AF3_A7D109ECD0B9'.

サインインしてコメントする。


Umar
Umar 2024 年 7 月 3 日

Hi Jun,

I did some experiment by creating a functional strip chart by utilizing the appropriate plotting functions available in Matlab, such as plot or stairs, to visualize the data series effectively and trying to find out if there were any bugs associated using ‘Stripchart’. Apparently there seems to be no issue with it.

>> % Create a time vector time = 0:0.1:10;

% Generate some sample data data1 = sin(time); data2 = cos(time);

% Create a figure for the strip chart figure; subplot(2,1,1); plot(time, data1, 'DisplayName', 'Sin Data'); title('Sin Data');

subplot(2,1,2); plot(time, data2, 'DisplayName', 'Cos Data'); title('Cos Data');

% Print out the results disp('Strip Chart Data:'); disp(['Time: ', num2str(time)]); disp(['Sin Data: ', num2str(data1)]); disp(['Cos Data: ', num2str(data2)]);

So, it sounds like you have to ensure that the syntax used to access the stripchart data is correct. Double-check the spelling and capitalization of 'StripChart' in your code. Confirm that the class reference 'Interface.4FCE6E77_A334_46E3_9AF3_A7D109ECD0B9' is accurate and corresponds to the correct object containing the stripchart data. Make sure that all necessary libraries or dependencies required for accessing stripchart data are properly imported and initialized in your HYSYS project. Hopefully, following these suggestions, it will help accomplish your goal.

  1 件のコメント
Jun Jie
Jun Jie 2024 年 7 月 3 日
Hi Umar,
I thank you for the effort! It is really nice of you... however the stripchart I am trying to access is from Hysys software...
Not trying to generate a stripchart from MATLAB myself.
Do you think you cna help me further with this? :(

サインインしてコメントする。


Umar
Umar 2024 年 7 月 3 日
Hi Jun,
My reason behind generating a stripchart from MATLAB myself was due to finding any bug that could cause stripchart error and this not appear to be an issue. However, there is issue when trying to access stripchart using Hysys software. I will do my best to help you resolve this problem. Send me the text file of code which is causing this error
>> % Access the stripchart data stripchart = hysys.ActiveDocument.StripChart; Unrecognized method, property, or field 'StripChart' for class 'Interface.4FCE6E77_A334_46E3_9AF3_A7D109ECD0B9'.
I will take a look and work together as a team to resolve this issue. However, due to 4th of July break, it will take some time if that is okay with you. Also, wish you and your family, happy 4th of July.
  1 件のコメント
Jun Jie
Jun Jie 2024 年 7 月 3 日
Hi Umar, this is really nice of you! :)
Text file of code thats causing this error is
>> % Access the stripchart data stripchart = hysys.ActiveDocument.StripChart;
Output is
Unrecognized method, property, or field 'StripChart' for class 'Interface.4FCE6E77_A334_46E3_9AF3_A7D109ECD0B9'.
In essence, i want to access strip chart on hysys dynamic model, and export the data onto excel, all using code to do so.
i tried using VBA also, but face the same issue with API where it is unable to directly access strip chart...
my main goal is to get my accumulated output from the process that run.
Currently, i am only able to extract molar flow rate at that current time, which is singular, but i want accumulated, as my process is running for days.

サインインしてコメントする。


Umar
Umar 2024 年 7 月 3 日
Hi Jun,
After reading your detailed comments, there is alternative approach to resolve this issue. Export the data from the HYSYS dynamic model to a file format that MATLAB can read. This can be done by saving the data in a compatible format like CSV or Excel from HYSYS. Then, use MATLAB to read the exported data file. You can use functions like readmatrix or xlsread to import the data into MATLAB variables. Once the data is imported into MATLAB, you can process and manipulate it as needed. Perform calculations, filtering, or any other operations required to extract the accumulated output data. MATLAB provides a wide range of functions for data analysis and manipulation, allowing you to extract the specific information you need from the data.After processing the data in MATLAB, you can export the results to Excel. Use functions like writematrix or writetable to write the data to an Excel file. Please ensure that the data is formatted correctly in Excel for easy interpretation and further analysis. Here is a simplified example demonstrating how to read data from a CSV file, process it, and export the results to Excel:
% Read data from CSV file
data = readmatrix('hysys_data.csv');
% Process data (example: calculate sum of a column)
sum_data = sum(data(:, 2));
% Export processed data to Excel
xlswrite('output_data.xlsx', sum_data, 'Sheet1', 'A1');
By following these steps and customizing the data processing operations in MATLAB, you can effectively access and export strip chart data from a HYSYS dynamic model to Excel. This approach provides flexibility and control over the data extraction process, enabling you to retrieve the accumulated output data efficiently.
  1 件のコメント
Jun Jie
Jun Jie 2024 年 7 月 3 日
that will not work as i want it automated. i do not want to manually have to extract from hysys! :)

サインインしてコメントする。


Umar
Umar 2024 年 7 月 3 日
Hi Jun,
I know that you already know how to establish a connection between MATLAB and the HYSYS application who can be done using MATLAB's built-in functions for ActiveX or COM object communication.
% Create a connection to the HYSYS application hysys = actxserver('HYSYS.Application');
Once the connection is established, you know how to access the stripchart data within HYSYS and identifying the specific stripchart of interest and extract the data points. However, I will still provide code for it.
% Access the stripchart data from HYSYS stripchart = hysys.ActiveDocument.Flowsheet.Streams.Item('YourStripchartName'); data = stripchart.Data;
Once retrieving the data from the stripchart, you can export it to MATLAB for further analysis or processing & save the data to a MATLAB variable or a file for future use.
% Export the stripchart data to MATLAB save('stripchart_data.mat', 'data');
Finally, it is essential to close the connection to the HYSYS application once the data extraction is complete.
% Close the connection to the HYSYS application hysys.Quit;
Feel free to modify these steps based upon your code structure.
  1 件のコメント
Jun Jie
Jun Jie 2024 年 7 月 4 日
Hi Umar, am a bit confused.
Strip chart is not a stream. Nor is it in the flowsheet.... it is a seperate tab, something simlar to event scheduler

サインインしてコメントする。


Umar
Umar 2024 年 7 月 4 日
編集済み: Walter Roberson 2024 年 7 月 4 日
Hi Jan,
I was not aware that HYSYS is so sensitive, replace Flowsheet.Streams with StripCharts in the code, the correct property is accessed, allowing for the successful extraction of stripchart data from HYSYS.
% Access the stripchart data from HYSYS
stripchart = hysys.ActiveDocument.StripCharts.Item('YourStripchartName');
data = stripchart.Data;
  6 件のコメント
Rik
Rik 2024 年 7 月 4 日
On mobile browsers you still have the legacy editor. Even without a working preview, your post should show up as expected.
On the old editor you need to make sure your code starts with 2 spaces and blank lines also contain 2 spaces.
The levels are regularly updated (but not live), so they should resolve automatically after a while. What should your badge be? I can contact someone at Mathworks if you would like someone to look into this.
Umar
Umar 2024 年 7 月 4 日
Thanks for your advice, good job. Well, if they are regularly updated then I will wait. If it’s not resolved by then, the last option would be the one you suggested by getting in touch with Mathworks.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by