如何在MATLAB GUI中为静态文本赋值?
如何使用MATLAB将信号发送到IP地址的端口?
事实上,我已经通过Wifi将机器人汽车与PC连接起来,我已经确定FF000400FF机器人接收到的信号将驱动汽车前进.我通过TCP和UDP工具对此进行了测试,结果没问题.所以我认为使用MATLAB发送这个信号也应该没问题.
我的代码是:
t = tcpip('192.168.1.1',2001);
fopen(t);
a=dec2hex(1095216922879); %FF000400FF(H)
fprintf(t,a)
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我一直在努力,但失败了.
在Matlab中考虑这个:
>> clear M, M(:,:,:,1,:)=rand(10,10,2,1,5); size(M)
ans =
10 10 2 1 5
>> clear M, M(:,:,:,1,:)=rand(10,10,1,1,5); size(M)
ans =
10 10 5
>> clear M, M(:,:,1,1,:)=rand(10,10,1,1,5); size(M)
ans =
10 10 1 1 5
Run Code Online (Sandbox Code Playgroud)
为什么第二个代码行不像第一个和第三个那样?(即保持阵列的5D形状)
是否允许冒号代表单身维度?(第二个代码行中的第三维)
你能否在文件中找出相应的段落?
如何使用带有逻辑的f-string格式化int为float?我想ppl是True格式化num为2位小数,如果ppl是False格式化为它是什么.
有点像string = f'i am {num:.2f if ppl else num}'但这不起作用.下面的代码演示了如果可能的话我想用更简单的f字符串实现的行为:
ppl = True
num = 3
string = f'I am {num:.2f}' if ppl else f'I am {num}'
print(string)
#if ppl False
#=> i am 3
#if ppl True
#=> i am 3.00
Run Code Online (Sandbox Code Playgroud) 在指南中我可以找到:
"如果要将Ember应用程序嵌入到现有站点中,则可以通过提供rootElement属性为特定元素设置事件侦听器:
window.App = Ember.Application.create({
rootElement: '#sidebar'
});
Run Code Online (Sandbox Code Playgroud)
"
请举例说明如何正确使用它.
我有一个包含多个列的数据框,其中两列是分组变量.
>>> df2
Groupvar1 Groupvar2 x y z
0 A 1 0.726317 0.574514 0.700475
1 A 2 0.422089 0.798931 0.191157
2 A 3 0.888318 0.658061 0.686496
....
13 B 2 0.978920 0.764266 0.673941
14 B 3 0.759589 0.162488 0.698958
Run Code Online (Sandbox Code Playgroud)
我想创建一个新的数据帧,它保存origianl df中每个数据点与对应于其子组的平均值之间的差异.
所以首先使用分组平均值制作新的df:
>>> grp_vars = ['Groupvar1','Groupvar2']
>>> df2_grp = df2.groupby(grp_vars)
>>> df2_grp_avg = df2_grp.mean()
>>> df2_grp_avg
x y z
Groupvar1 Groupvar2
A 1 0.364533 0.645237 0.886286
2 0.325533 0.500077 0.246287
3 0.796326 0.496950 0.510085
4 0.774854 0.688732 0.487547
B 1 …Run Code Online (Sandbox Code Playgroud) 我想根据 numpy 3d 数组中的值创建一个 numpy 2d 数组,使用另一个 numpy 2d 数组来确定在轴 3 中使用哪个元素。
import numpy as np
#--------------------------------------------------------------------
arr_3d = np.arange(2*3*4).reshape(2,3,4)
print('arr_3d shape=', arr_3d.shape, '\n', arr_3d)
arr_2d = np.array(([3,2,0], [2,3,2]))
print('\n', 'arr_2d shape=', arr_2d.shape, '\n', arr_2d)
res_2d = arr_3d[:, :, 2]
print('\n','res_2d example using element 2 of each 3rd axis...\n', res_2d)
res_2d = arr_3d[:, :, 3]
print('\n','res_2d example using element 3 of each 3rd axis...\n', res_2d)
Run Code Online (Sandbox Code Playgroud)
结果...
arr_3d shape= (2, 3, 4)
[[[ 0 1 2 3]
[ 4 5 6 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有箭头功能的matploblib绘制一些箭头.但我想使用数组单独选择每个箭头的长度.
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.quiver http://matplotlib.sourceforge.net/examples/pylab_examples/quiver_demo.html
在这些演示和文档,这是表明你可以按比例改变秤的单位(X,Y,宽度,高度,XY,英寸,......),有没有办法来定义一个规模为每个箭头?
我正在尝试使用Numpy和Matplotlib可视化2D平面切割3D图形来解释偏导数的直觉.
具体来说,我使用的函数是J(θ1,θ2)=θ1^ 2 +θ2^ 2,我想在θ2= 0处绘制θ1-J(θ1,θ2)平面.
我设法使用下面的代码绘制2D平面,但2D平面和3D图形的叠加不太正确,2D平面略微偏离,因为我希望平面看起来像在θ2处切割3D = 0.
如果我可以借鉴你的专业知识,那将是很好的,谢谢.
def f(theta1, theta2):
return theta1**2 + theta2**2
fig, ax = plt.subplots(figsize=(6, 6),
subplot_kw={'projection': '3d'})
x,z = np.meshgrid(np.linspace(-1,1,100), np.linspace(0,2,100))
X = x.T
Z = z.T
Y = 0 * np.ones((100, 100))
ax.plot_surface(X, Y, Z)
r = np.linspace(-1,1,100)
theta1_grid, theta2_grid = np.meshgrid(r,r)
J_grid = f(theta1_grid, theta2_grid)
ax.contour3D(theta1_grid,theta2_grid,J_grid,500,cmap='binary')
ax.set_xlabel(r'$\theta_1$',fontsize='large')
ax.set_ylabel(r'$\theta_2$',fontsize='large')
ax.set_zlabel(r'$J(\theta_1,\theta_2)$',fontsize='large')
ax.set_title(r'Fig.2 $J(\theta_1,\theta_2)=(\theta_1^2+\theta_2^2)$',fontsize='x-large')
plt.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)
这是代码输出的图像:
我正在使用GUIDE构建一个简单的MATLAB gui.我有一个项目列表框.大多数情况下,它按预期工作,但有时(通常在我使用GUIDE编辑图形后)填充列表框会导致它消失,以及此消息:
Warning: single-selection listbox control requires a scalar Value
Control will not be rendered until all of its parameter values are valid
Run Code Online (Sandbox Code Playgroud)
这种行为无法调试!当我单步执行时,它按预期工作(我怀疑它是一种线程竞赛或其他东西).此外,在相同条件下重新启动MATLAB环境后,它通常会消失.
在此错误中找到的所有文档都涉及MATLAB的先前/古代版本(我使用的是R2010a).
任何有关此主题的想法或信息将不胜感激!
编辑:感谢米哈伊尔,我似乎已经解决了这个问题.我在这里发布我的代码以供将来参考.
经过大量的调试打印和疯狂点击之后,我发现有时候当您询问列表框选择的内容时,会得到一个空的结果.这个问题和其他问题使事情变得混乱.我把所有的写作交互都放到了一个集中的函数中,然后我写了一些测试代码,以确保事情保持原样.
请注意,这已经在我自己的环境(在R2010a上)进行了测试,而不是广泛的.此外,代码有点多余,但无论如何它让我感觉很好.(即itemcount不能小于0 ...)
function ensure_listbox_ok(handles)
%check to make sure it does not suck - ask what it has
thestrings = get(handles.listbox_files, 'String');
selection = get(handles.listbox_files, 'Value');
itemcount = length(thestrings);
betterselection = selection;
if(itemcount <= 0)
betterselection = 1;
else
if(selection > itemcount)
betterselection = itemcount;
end
end
%never use zero!!!! even …Run Code Online (Sandbox Code Playgroud) matlab user-interface intermittent race-condition matlab-guide
python ×5
matlab ×4
indexing ×2
matlab-guide ×2
matplotlib ×2
numpy ×2
3d ×1
arrays ×1
colon ×1
ember.js ×1
f-string ×1
intermittent ×1
pandas ×1
port ×1
python-3.x ×1
tcp-ip ×1
uicontrol ×1