How can I obtain the data from the scope for a waveform
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
John D'Errico
2014-3-7
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
2014-3-7
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
2014-3-7
编辑:Mischa Kim
2014-3-7
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
2014-3-7
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.
采纳的回答
Mischa Kim
2014-3-1
编辑:Mischa Kim
2014-3-1
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.
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 个评论
Shivakumar
2014-3-5
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
2014-3-5
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
2014-3-6
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
2014-3-6
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
2014-3-6
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
2014-3-6
For the command
val_485 = simout(tout==4.85,2); This is the error I got.
??? Index exceeds matrix dimensions.
Mischa Kim
2014-3-6
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
2014-3-6
编辑:Shivakumar
2014-3-6
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
2014-3-8
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
2014-3-8
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
2014-3-10
编辑:Mischa Kim
2014-3-10
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
2014-3-10
simout.signals.values(find(simout.time==4.85))
ans =
Empty matrix: 0-by-1
This is the result I got, Kim
Mischa Kim
2014-3-10
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
2014-3-10
I still get the same problem. I use MATLAB 7.6.0. Do you think different versions is making the difference here?
Mischa Kim
2014-3-10
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
2014-3-11
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
2014-3-11
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. :)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)