Plotting a graph using indexed values

조회 수: 11 (최근 30일)
Christine Nee
Christine Nee 2017년 7월 21일
댓글: Christine Nee 2017년 7월 24일
I am trying to generate a plot. I use Max_value_Force and Min_value_Force to find the max and min values then I find where they are indexed. I then take the index and go back to my data and find when the force was min and max. After that I want to plot ALL the values between the max and min times as a plot with time (t) vs force (f). The reason why I am experimenting with time for now is because I am trying to figure out what full cycles look like on something I am analyzing. when I run this code I get an error.
[Max_value_force,I] = max(f(:))
Time_Max_Force = t(I)
[Min_value_force,I] = min(f(:))
Time_Min_Force = t(I)
plot(t(Time_Min_Force:Time_Max_Force),f(Time_Min_Force:Time_Max_Force))
"Warning: Integer operands are required for colon operator when used as index "
How do I get this to successfully generate a plot

답변 (1개)

Jess Lovering
Jess Lovering 2017년 7월 21일
It looks like you are trying to use the max and min values as the indices instead of the index values. See example:
[Max_value_force,maxI] = max(f(:))
Time_Max_Force = t(maxI)
[Min_value_force,minI] = min(f(:))
Time_Min_Force = t(minI)
plot(t(minI:maxI),f(minI:maxI))
  댓글 수: 1
Christine Nee
Christine Nee 2017년 7월 24일
Doesn't entirely work.
So here is my code. I am unable to plot nor put into array those values. I get an error with your revised code and my original code:
%Finding max values and creating a seperate array
[Max_Value_Force,maxI] = max(f(:))
Time_Max_Force = t(maxI)
%Max_Value_Force_Times_Array = t(I+1)
[Min_Value_Force,minI] = min(f(:))
Time_Min_Force = t(minI)
%Create the table with those values
%table has alternating values
Table = [Max_Value_Force Time_Max_Force; Min_Value_Force Time_Min_Force]
plot(t(minI:maxI),f(minI:maxI))
Any ideas on how to get this working as a plot and also on a table?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by