67 views (last 30 days)

Show older comments

Rahul on 30 Jul 2024 at 0:54

Answered: Rahul about 9 hours ago

Accepted Answer: Piyush Kumar

Open in MATLAB Online

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 Comment Show -1 older commentsHide -1 older comments

Show -1 older commentsHide -1 older comments

Athanasios Paraskevopoulos on 30 Jul 2024 at 1:03

#### Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2141296-how-to-determine-the-minimum-point-of-a-plot#comment_3223716

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

Sign in to comment.

Sign in to answer this question.

### Accepted Answer

Piyush Kumar on 30 Jul 2024 at 3:28

Edited: Piyush Kumar on 30 Jul 2024 at 3:31

@Rahul,

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.

##### 0 Comments Show -2 older commentsHide -2 older comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

### More Answers (2)

Abhinaya Kennedy on 30 Jul 2024 at 3:25

Open in MATLAB Online

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 Comments Show 6 older commentsHide 6 older comments

Show 6 older commentsHide 6 older comments

Rahul on 30 Jul 2024 at 5:59

#### Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2141296-how-to-determine-the-minimum-point-of-a-plot#comment_3223806

Edited: Rahul about 24 hours ago

Hi,

Thanks a lot. But, I'm little confused regarding the "min_index".

Can you please elaborate the role of min_index in the given function?

I tried the function. Its working only partially. The second output arguement (i.e, the min_index) is not showing in result.

rgds,

rahul

Walter Roberson on 30 Jul 2024 at 6:44

#### Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2141296-how-to-determine-the-minimum-point-of-a-plot#comment_3223851

In that code, min() will be applied along the first non-scalar dimension of data . In the second output argument, min() will return the indices of the minimum value relative to that first non-scalar dimension . The result will be an array with that first non-scalar dimension "collapsed"

For example if data is 1 x 3 x 2 then the output will be 1 x 1 x 2 reflecting the indices of the minimums of (1,:,1) and (1,:,2)

It is common for min() to be applied to a vector, in which case the second output will be the index into the vector where the minimum occurs.

Rahul on 30 Jul 2024 at 7:59

#### Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2141296-how-to-determine-the-minimum-point-of-a-plot#comment_3223921

Thanks everyone.

your comments are indeed helpful.

Walter Roberson about 24 hours ago

#### Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2141296-how-to-determine-the-minimum-point-of-a-plot#comment_3224011

Open in MATLAB Online

You need to assign two outputs from the function

[min_value, min_index] = find_plot_minimum(YourDataGoesHere)

Rahul about 11 hours ago

#### Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2141296-how-to-determine-the-minimum-point-of-a-plot#comment_3225166

Edited: Rahul about 11 hours ago

Open in MATLAB Online

Hi Walter Roberson,

Thanks a lot. I followed your suggestion. Still I guess something is wrong at my side which results in only 1st arguement at output and not the second.

Kindly advice the correction plz.

code as below

function [min_value, min_index] = find_plot_minimum(data)

% Assuming data is a vector

global data;

for i=999:max(length(data.variable.t))

for j=60:max(length(data.variable.x))-1

if isempty(data.variable.gradpressure(i,j))

min_value = NaN;

min_index = NaN;

return;

end

[min_value, min_index] = min(data.variable.gradpressure(i,j));

end

end

ans =

-8.8415

Walter Roberson 15 minutes ago

#### Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2141296-how-to-determine-the-minimum-point-of-a-plot#comment_3225561

Open in MATLAB Online

length() is already a scalar, so max(length) is not doing anything useful for you.

Declaring data as a global while data is already passed in, is going to be an error soon.

You are overwriting min_value and min_index every iteration of your loops.

data.variable.gradpressure(i,j) will never be empty. If data.variable.gradpressure is numeric then (i,j) indexing will result in a scalar numeric output; If data.variable.gradpressure is a cell array, then (i,j) indexing will result in a cell array containing something

Anyhow, you need to run the function and record both outputs. You would invoke it with something like

[Output_min_value, Output_min_index] = find_plot_minimum(YourData)

This is invoking the code, not what should go onto the function line.

Rahul about 4 hours ago

#### Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2141296-how-to-determine-the-minimum-point-of-a-plot#comment_3225606

Edited: Rahul 5 minutes ago

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 3 minutes ago

#### Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/2141296-how-to-determine-the-minimum-point-of-a-plot#comment_3225841

Open in MATLAB Online

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)

Sign in to comment.

Rahul 20 minutes ago

Open in MATLAB Online

Hi all,

I found a solution for the above problem by removing the function as below.

However, the code gives the the index no. displayed wrongly (index. no. is always found to be 1). I understand that this may be due to the loop used. But, the loop is used by me as I need the search for maximum gradient to be restricted (only for i=999, j=60).

Kindly advice me a solution.

% Assuming data is a vector

for i=999:numel(data.variable.t)

for j=60:numel(data.variable.x)-1

if isempty(data.variable.gradpressure(i,j))

max_value = NaN;

max_index = NaN;

return;

end

[max_value,max_index] = max(data.variable.gradpressure(i,j));

end

end

disp(max_value)

disp(max_index)

% Determine the coordinates in 2-dimension for the maximum point

H00 = 1:5:50;

S00 = 10:-1:1;

[H0,S0] = meshgrid(H00,S00);

[max_row, max_col] = ind2sub(size(max_value), max_index);

x_max_grad = H0(max_row, max_col);

y_max_grad = S0(max_row, max_col);

R = sqrt(x_max_grad.^2+y_max_grad'.^2);

with rgds

##### 0 Comments Show -2 older commentsHide -2 older comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

### See Also

### Categories

MATLABLanguage FundamentalsData TypesNumeric TypesLogical

Find more on **Logical** in Help Center and File Exchange

### Tags

- transferred

### Community Treasure Hunt

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

Start Hunting!

**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

- América Latina (Español)
- Canada (English)
- United States (English)

Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français

- United Kingdom(English)

Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)

Contact your local office