How to determine the minimum point of a plot?

23 ビュー (過去 30 日間)
Rahul
Rahul 2024 年 7 月 30 日
コメント済み: Walter Roberson 2024 年 7 月 31 日
Hi,
I have a plot as attached herewith in which the value of the point as shown by arrow mark is to be determined and compared to a reference value. It is plotted at a time step of 999 (t ranges from 1 to 1000).
global data;
cp=0;
for i=999:max(length(data.variable.t))
for j=60:max(length(data.variable.x))-1
if data.variable.curvepressure(i,j) <= -10.2661
disp(data.variable.curvepressure(i,j))
cp=1;
break
end
end
end
The above code is not working and need your advice please.
  1 件のコメント
Athanasios Paraskevopoulos
Athanasios Paraskevopoulos 2024 年 7 月 30 日

Good! What exactly is your question? Do you want to create this plot?

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

採用された回答

Piyush Kumar
Piyush Kumar 2024 年 7 月 30 日
編集済み: Piyush Kumar 2024 年 7 月 30 日
The code you have written will display the values less than or equal to -10.2661. The break you are using will break only from the inner loop. The outer loop continues execution.
From the subject "How to determine the minimum point of a plot?", it seems like you want to find global minima of the plot. However, the provided code does not find the global minimum of the plot.

その他の回答 (1 件)

AKennedy
AKennedy 2024 年 7 月 30 日
A function can help you with finding the minimum value of your plot. You can define the function as follows:
Inputs:
  • data: The data to be analyzed. This could be a vector, matrix, or structure depending on the data format.
Outputs:
  • min_value: The minimum value found in the data.
  • min_index: The index of the minimum value in the data.
function [min_value, min_index] = find_plot_minimum(data)
% Assuming data is a vector
if isempty(data)
min_value = NaN;
min_index = NaN;
return;
end
[min_value, min_index] = min(data);
end
You can use this as an outline to find the minimum value from your plot and tweak it to suit your needs.
You can get additional info on the min function here: https://www.mathworks.com/help/matlab/ref/min.html
  8 件のコメント
Rahul
Rahul 2024 年 7 月 31 日
編集済み: Rahul 2024 年 7 月 31 日
Hi Walter,
Thanks once again. Its difficult to pass the data as you have shown in as above. The name of my data is "data" uploaded in workspace. This is because the no. of input data is large and hence it is uploaded in workspace. But it seems the code is unable to read it.
Can you tell me how to do it?
I'm getting error msg
Not enough input arguments.
Error in find_plot_minimum (line 5)
for i=998:length(data.variable.t)
Walter Roberson
Walter Roberson 2024 年 7 月 31 日
If it is "uploaded in workspace" then you should be able to just reference it by name.
Not enough input arguments.
You need to pass data to the function.
Variables are passed by reference, not by value, so as long as it is known in the calling workspace, passing it in is fast and cheap.
%calling routine
YourData = .... something appropriate
[Output_min_value, Output_min_index] = find_plot_minimum(YourData)

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by