Matlab中的稀疏随机矩阵,其值不同于[0,1](Sparse random matrix in Matlab with values in different range than [0,1])
如何在Matlab中创建一个稀疏随机矩阵,其值范围不同于默认值
[0,1]
,比如[-1,1]
? 我试过的两件事显然不起作用的是:p = 2 * sprand(5,5,0.1) - 1
返回
>> p = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -0.4850 -1.0000 -1.0000 0.6814 -1.0000 -1.0000 -1.0000 -1.0000
和
p = ceil(sprand(5,5,0.1)); p(find(p)) = 2 * rand(5) - 1; full(p)
返回
>> ans = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3112 0 0 0.3112 0 0 0 0
我想要一个不涉及任何循环的解决方案,只使用矩阵操作或内置Matlab函数。
How do I create a sparse random matrix in Matlab with a value range different from the default
[0,1]
, say[-1,1]
? Two things I've tried that obviously didn't work are:p = 2 * sprand(5,5,0.1) - 1
which returns
>> p = -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -0.4850 -1.0000 -1.0000 0.6814 -1.0000 -1.0000 -1.0000 -1.0000
And
p = ceil(sprand(5,5,0.1)); p(find(p)) = 2 * rand(5) - 1; full(p)
which returns
>> ans = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3112 0 0 0.3112 0 0 0 0
I would like a solution that doesn't involve any looping and that only uses matrix manipulations or built-in Matlab functions.
原文:https://stackoverflow.com/questions/30282677
最满意答案
你可以:
- 保存当前时间戳,
- 发出http请求,
- 得到http响应,
- 并在响应到达后立即获取时间戳并计算时间差。
或者,你可以
- 创建WebView
- 设置WebViewClient
- 使用它的回调 - onPageLoaded,onPageFinished,onPageStarted等...
请点击此处: http : //developer.android.com/reference/android/webkit/WebViewClient.html
You could:
- save the current timestamp,
- make a http request,
- get the http response,
- and get the timestamp as soon as your response arrives and calculate the difference in time.
Or, you could
- Create a WebView
- Set a WebViewClient
- Use its callbacks - onPageLoaded, onPageFinished, onPageStarted, etc ...
Check here: http://developer.android.com/reference/android/webkit/WebViewClient.html
相关问答
更多-
似乎getSpeed()方法并不总是可靠的,特别是在低速和gps覆盖率不是最佳时。 你可以看看这个问题 , 这个问题都是关于getSpeed()的替代方法。 然而, android developper页面表示,使用Google Location API可以获得更好的性能。 所以看来,选择取决于你的应用的使用情况:如果你的目标是慢速移动的地区与GPS覆盖差(走在木头),使用你自己的实施。 具有良好GPS覆盖范围的区域速度很快,请使用Google Location API。 希望它对你有所帮助。 It see ...
-
我认为这可能有助于http://www.vogella.de/articles/AndroidSensor/article.html和这一个http://developer.android.com/resources/samples/AccelerometerPlay/index.html I think this may help http://www.vogella.de/articles/AndroidSensor/article.html and this one http://developer. ...
-
正如您已经建议的那样,您需要存储整个时间跨度的所有值。 原因在于你不知何故需要“忘记”旧值对移动平均线的贡献。 如果你不知道这些值在哪里(即,如果你不存储它们),那么你无法做到这一点。 在你的情况下,15分钟每秒1个值等于15 * 60 = 900个数据点,应该是OK。 请注意,每次更新时不需要对整个数组执行求和:您可以根据数据点数,新值以及此时“忘记”的值计算新的移动平均值: new_average = (n * old_average - x_forget + x_new) 在这里, n是数据点的数量 ...
-
尝试Firefox的YSlow插件,它会告诉你它在哪里“错误” try YSlow plugin for firefox, it will tell you where it goes 'wrong'
-
雅虎保持速度优化的良好总结: http://developer.yahoo.com/performance/rules.html 您可以使用FireSug插件YSlow来测量您的网站: http://developer.yahoo.com/yslow/ Yahoo maintain a good summary of speed optimisations: http://developer.yahoo.com/performance/rules.html You can measure your site ...
-
Android LocationServices getLastLocation将速度返回为0(Android LocationServices getLastLocation returns speed as 0)[2023-10-07]
我不确定这是否是你要找的: https : //developer.android.com/reference/android/location/Location.html#getSpeed() 但是getSpeed作为默认值返回0.0是“正常的”,因为你的位置没有速度(如文档中所示)。 I'm not sure if this is what you're looking for: https://developer.android.com/reference/android/location/Locat ... -
名称空间android.location包含许多有用的类。 基本上你需要的是使用Context.getSystemService(Context.LOCATION_SERVICE) ,然后使用LocationManager.requestLocationUpdates()你可以订阅监听提供者的位置更新。 要确定侦听LocationManager.GPS_PROVIDER所需的速度。 从Location您可以调用getSpeed() 。 当然,确定速度需要适当数量的卫星修复,因此给定的位置结果可能并不总是包含 ...
-
你可以: 保存当前时间戳, 发出http请求, 得到http响应, 并在响应到达后立即获取时间戳并计算时间差。 或者,你可以 创建WebView 设置WebViewClient 使用它的回调 - onPageLoaded,onPageFinished,onPageStarted等... 请点击此处: http : //developer.android.com/reference/android/webkit/WebViewClient.html You could: save the current ti ...
-
Facebook为此发布了一个库: https://github.com/facebook/network-connection-class 图书馆描述: 收听应用中的当前网络流量并对网络质量进行分类。 Facebook released a library for this: https://github.com/facebook/network-connection-class Library Description: Listen to current network traffic in the a ...
-
首先阅读本文以了解如何获得GPS修复。 您可以在位置侦听器中的onLocationChanged()回调中调用getSpeed()。 First read this article to learn how to get GPS fixes. You can call getSpeed() in your location listener, in the onLocationChanged() callback.