我想操纵一个单元格数组,并使单元格数组的某些索引包含空矩阵[].我似乎无法弄清楚如何做到这一点:
>> yy=num2cell(1:10)
yy =
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
>> yy{1:2:end}=[]
??? The right hand side of this assignment has too few values to satisfy
the left hand side.
>> yy(1:2:end) = []
yy =
[2] [4] [6] [8] [10]
Run Code Online (Sandbox Code Playgroud)
呸! 似乎无法做我想做的事.我想在单元格数组中留下空元素,例如
[] [2] [] [4] [] [6] [] [8] [] [10]
Run Code Online (Sandbox Code Playgroud)
有什么建议?我的索引向量可以是任意的,无论是索引形式还是布尔形式,都不一定是[1 3 5 7 9].
我试图在我们的内部库中找到所有MATLAB函数的所有输入/输出.我是新的(第一次)正则表达式,并一直试图在Python的re库中使用多行模式.
MATLAB函数语法如下:
function output = func_name(input)
Run Code Online (Sandbox Code Playgroud)
签名可以跨越多行.
我开始使用如下模式:
re.compile(r"^.*function (.*)=(.*)\([.\n]*\)$", re.M)
Run Code Online (Sandbox Code Playgroud)
但我一直得到一个不受支持的模板操作符错误.任何指针都很赞赏!
编辑:
我现在有:
pattern = re.compile(r"^\s*function (.*?)= [\w\n.]*?\(.*?\)", re.M|re.DOTALL)
Run Code Online (Sandbox Code Playgroud)
给出如下匹配的匹配:
function [fcst, spread] = ...
VolFcstMKT(R,...
mktVol,...
calibrate,...
spread_init,...
fcstdays,...
tsperyear)
if(calibrate)
if(nargin < 6)
tsperyear = 252;
end
templen = length(R)
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么它会给出额外的线而不是在第一线停下来)?
[r,c,d] = size(rgbImage); %# Get the image dimensions
Run Code Online (Sandbox Code Playgroud)
什么是r,c,d站在这里?
我认为这是一个简单的问题.我想要:
a = 1.154648126486416;
Run Code Online (Sandbox Code Playgroud)
成为:
a = 1.154;
Run Code Online (Sandbox Code Playgroud)
并不是:
a = 1.15000000000;
Run Code Online (Sandbox Code Playgroud)
如何在不使用的情况下执行此操作format('bank').
我需要计算一些变量的均值,标准差和其他值,我想知道如何使用循环来获得优势.我有5个数据电极.所以要计算每个的平均值,我这样做:
mean_ch1 = mean(ch1);
mean_ch2 = mean(ch2);
mean_ch3 = mean(ch3);
mean_ch4 = mean(ch4);
mean_ch5 = mean(ch5);
Run Code Online (Sandbox Code Playgroud)
我想要的是能够将代码压缩成一行左右.我试过的代码不起作用:
for i = 1:5
mean_ch(i) = mean(ch(i));
end
Run Code Online (Sandbox Code Playgroud)
我知道这段代码是错误的,但它传达了我想要完成的想法.我想最终得到5个由循环命名的独立变量或一个包含所有5个变量的单元数组,以便于调用.我知道必须有一种方法来编写这段代码我只是不知道如何实现它.
我在我正在处理的代码中有一行代码:
feval('func_name', myArg);
Run Code Online (Sandbox Code Playgroud)
它有效,但我想知道它在哪里func_name.我无法介入feval,看看它在哪里找到func_name.代替(或除)只是做func_name,我怎么能得到MATLAB告诉我在那里找到了吗?
我想知道这是否可行.我的代码看起来像这样:
indexStop = find(firstinSeq(x,4) ~= ...
littledataPassed(y:length(littledataPassed),4), 1, 'first');
for z= 0:(n-1)
indexProcess = find((littledataPassed(y:y+indexStop-1,6) == 1 & ...
littledataPassed(y:y+indexStop-1,2) == firstinSeq(x,2) & ...
littledataPassed(y:y+indexStop-1,5) == z), 1, 'first');
if isempty(indexProcess)
msgLength[n](countmsgLength[n],:)= [firstinSeq(x,:) [0 0 0 0 0 0]];
else
msgLength[n](countmsgLength[n],:)= [firstinSeq(x,:) ...
littledataPassed(y+indexProcess-1,:)];
end
countmsgLength[n]= countmsgLength[n] + 1;
end
Run Code Online (Sandbox Code Playgroud)
我希望在任何地方将读取[n]切换到实际值n,这样我就可以使用它将数据添加到格式的九个不同变量中msgLength#.我试过搜索教程,但没有看到任何关于这个主题的内容.
我有一个自定义函数,它返回0或1取决于两个给定的输入:
function val = myFunction(val1, val2)
% logic to determine if val=1 or val=0
end
Run Code Online (Sandbox Code Playgroud)
如何在x,y由以下meshgrid生成的坐标上创建函数的等高线图?
meshgrid(0:.5:3, 0:.5:3);
Run Code Online (Sandbox Code Playgroud)
该图仅显示功能的位置0或1等高线图上.
我正在评估一个简单的函数:
y = (2*x)/sqrt( 1 + x.^2 );
Run Code Online (Sandbox Code Playgroud)
其中x包含大约100个值的向量在哪里.但是,y在这种情况下,MATLAB 等于单个标量值.如果我做:
y = 2*x;
Run Code Online (Sandbox Code Playgroud)
我y按预期得到了一个值向量.如果我做:
y = x.^2;
Run Code Online (Sandbox Code Playgroud)
我也y按预期得到了一个值向量.
为什么上面的等式y = (2*x)/sqrt( 1 + x.^2 );给出单个值而不是值向量?
我想在MATLAB图中轴外的每个数据点上创建一条带有圆形标记的线,类似于
line([x1 x2],[y1 y2],'Color','k','Marker','o')
Run Code Online (Sandbox Code Playgroud)
会产生。
要将线对象放置在轴外,我只是尝试使用annotation:
annotation('line',phi1([x1 x2]),phi2([y1 y2]),'Color','k','Marker','o')
Run Code Online (Sandbox Code Playgroud)
其中phi1和phi2是适当的坐标转换,以适合当前图形的坐标x和y轴内。
我期望这行得通,因为线对象具有marker属性。但是,通过annotation,我收到以下错误消息:
Error using matlab.graphics.shape.Line/set
There is no Marker property on the Line class.
Error in matlab.graphics.chart.internal.ctorHelper (line 8)
set(obj, pvpairs{:});
Error in matlab.graphics.shape.Line
Error in annotation (line 128)
h = matlab.graphics.shape.Line(aargs{:});
Run Code Online (Sandbox Code Playgroud)
同样,用该annotation函数绘制矩形时,不能设置该Curvature属性。似乎annotation不支持这些类型的属性,即使它像line或rectangle函数那样创建线或矩形对象。我尝试摆弄注解句柄和子项,但没有成功。
有任何解决方法的想法吗?