You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How can I obtain the data from the scope for a waveform
5 views (last 30 days)
Show older comments
Hi, I need data from the scope at a certain time. The waveform obtained is sinusodial. I've connected "To simulink" from where I want to get the data. I need to get the value of the waveform at time 4.85. I think this is one of the basic questions. I am not so sure of syntax of the command. Please help.
4 Comments
John D'Errico
on 7 Mar 2014
It looks like you got an answer, but you are not using it properly. Your issue, not that of the person who answered the question.
Shivakumar
on 7 Mar 2014
No, I didn't get the answer. I tried his example to my problem. I am not able to get solution to my problem. If I got the answer, I have accepted his answer. Please check that my question is explained in the last two comments. I am still in need of the solution.
Mischa Kim
on 7 Mar 2014
Edited: Mischa Kim
on 7 Mar 2014
I have to concur with John, I believe I did provide an answer. One which you even got to work. I believe so especially because I am confident in your ability to check out your simout1 object, identify its time vector component and adapt the syntax I showed you accordingly.
I am sure you did not mean to, but you might come across as one of those constantly dissatisfied users that eventually are flagged (figuratively) in the contributors community.
Shivakumar
on 7 Mar 2014
Kim, Please don't take me wrong. I flagged it because I want to make the question active and to get the answer. I don't have any dissatisfaction or complaints on your given answer. There are no other wrong intentions, Kim. I thank you for taking time to answer my question. If you go throw my comments, you will understand my problem of not getting the required solution.
Accepted Answer
Mischa Kim
on 1 Mar 2014
Edited: Mischa Kim
on 1 Mar 2014
One option would be to add a Digital Clock block as shown below and set the sampling time to 4.85. This way this time stamp is automatically added to your time vector that is saved in the workspace.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174455/image.png)
In MATLAB you can then simply search for the data point at t=4.85, e.g.,
hold on
plot(tout,simout(:,2))
plot(tout(tout==4.85), simout(tout==4.85,2),'rs') % for the above model
22 Comments
Shivakumar
on 5 Mar 2014
Hi, I dont want to plot the data. I want the value at 4.85 seconds to be stored as a variable A in the M-file.
Shivakumar
on 5 Mar 2014
This is the syntax I have to get the maximum value of a waveform.
for i = 1: length(simout1.time(:,1))
if simout1.time(i,1) == 0.1
j = i;
break;
end
end
j
max_val = max(simout1.signals.values(j:end,1))
In the same way, I need a code to get the data exactly at 4.85 seconds.
Mischa Kim
on 6 Mar 2014
Just as shown above, I'd assume (since I do not know the exact structure of your data)
val_485 = simout1.signals.values(simout1.time(simout1.time(:,1)==4.85),1);
Shivakumar
on 6 Mar 2014
First I am trying the same kind of solution for the model example you gave above. This is the error I got when I used the above command.
??? Attempted to access simout1.time(:,1); index out of bounds because size(simout1.time)=[0,0].
Mischa Kim
on 6 Mar 2014
If you are using my example model you also need to use the attached code and variable names. In this case
val_485 = simout(tout==4.85,2);
will work. In my last comment I was trying to guess your data structure and come up with a solution. Notice that your workspace variable is called simout1 whereas mine is simout. So the following command "should" work for your model (and not mine)
val_485 = simout1.signals.values(simout1.time(simout1.time(:,1)==4.85),1);
Shivakumar
on 6 Mar 2014
For the command
val_485 = simout(tout==4.85,2); This is the error I got.
??? Index exceeds matrix dimensions.
Mischa Kim
on 6 Mar 2014
Double-click the simout block and set Save Format to Array. You probably have a different setting there. When I run the model I get in the MATLAB command window
val_485 = simout(tout==4.85,2)
val_485 =
-0.990546535966713
Shivakumar
on 6 Mar 2014
Edited: Shivakumar
on 6 Mar 2014
I got the same answer. But I tried the same to my model but I am not getting the result. Instead, it is showing that the matrix is empty. I've attached the model here. I need to find the value of both simouts at 4.85. I've tried different formats in simout. Please help. Thanks in advance.
John D'Errico
on 8 Mar 2014
My guess is that testing for t == 4.85 is a problem. Testing for (abs(t-4.85)<10*eps) might be a better idea. It might also resolve why the poster failed to get it to work.
Mischa Kim
on 8 Mar 2014
John, with the Digital Clock you can set an exact time stamp in the tout vector.
Shivakumar, what needs to be done (initialized) to run your model?
Mischa Kim
on 10 Mar 2014
Edited: Mischa Kim
on 10 Mar 2014
In this particular case only (there is a time stamp at t = 4.85) you can simply find the value with
simout.signals.values(find(simout.time==4.85))
The Digital Clock block is not necessary.
Shivakumar
on 10 Mar 2014
simout.signals.values(find(simout.time==4.85))
ans =
Empty matrix: 0-by-1
This is the result I got, Kim
Mischa Kim
on 10 Mar 2014
Shivakumar, I downloaded the model you attached in your last comment, and ran it. I get
simout.signals.values(find(simout.time==4.85))
ans =
1.6031
Shivakumar
on 10 Mar 2014
I still get the same problem. I use MATLAB 7.6.0. Do you think different versions is making the difference here?
Mischa Kim
on 10 Mar 2014
Possible, but I do not think so.
- Do you see the object simout in the workspace?
- When you type simout.signals.values and simout.time do you get the values of the two arrays?
Mischa Kim
on 11 Mar 2014
What happens, when you execute...
simout.time(end)
ans =
5
find(simout.time==4.85)
ans =
97001
simout.signals.values(ans)
ans =
1.6031
simout.signals.values(find(simout.time==4.85))
ans =
1.6031
Shivakumar
on 11 Mar 2014
I thank you Kim for your effort and time. This command helped me to get the answer.
val=simout.signals.values(97001)
I thank you very much. :)
More Answers (0)
See Also
Categories
Find more on Programmatic Model Editing 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!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
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
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
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)