在R2016b中,除了通常的char数据类型之外,MATLAB还引入了一种新的字符串数据类型.到目前为止,这么好,但它现在给了我很多我正在使用的JSONlab工具箱的问题.
例如,在R2015b中,loadjson返回1x3单元字符数组:
dd = loadjson('["Titi", "Toto", "Tata"]')
dd =
'Titi' 'Toto' 'Tata'
Run Code Online (Sandbox Code Playgroud)
但是在R2018a中,loadjson返回1x3 字符串数组:
dd = loadjson('["Titi", "Toto", "Tata"]')
dd =
1×3 cell array
{["Titi"]} {["Toto"]} {["Tata"]}
Run Code Online (Sandbox Code Playgroud)
为了不必在任何地方更改我的代码,我想修补loadjson例程以替换string它可能返回char类型的所有类型.例如,在以下单元格数组中:
test = { 'hello', "world", 0.3; 'how', 'are', "you"}
test =
2×3 cell array
{'hello'} {["world"]} {[0.3000]}
{'how' } {'are' } {["you" ]}
Run Code Online (Sandbox Code Playgroud)
我想替换所有字符串:
cellfun(@isstring, test)
ans =
2×3 logical array …Run Code Online (Sandbox Code Playgroud) 在将它们打印到A4尺寸纸张时,我无法理解如何渲染具有正确尺寸的html元素.
为了说明我的目的,我将我的代码简化为一个html页面,其中一个红色边框表应为210mmx297mm(A4纸张尺寸):
<!DOCTYPE html>
<html>
<head>
<style>
@page
{
size: 210mm 297mm portrait; /* Set paper size to A4 (portrait) */
}
html, body
{
width: 210mm;
padding:0;
margin: 0 auto; /* Left, right are auto for body to appear as centered on screen */
}
html
{
background: rgb(204,204,204); /* gray client window for screen (so as to emphase the body as looking as A4 paper) */
}
table
{
width:100%;
height:297mm;
-moz-box-sizing: border-box;
border: solid 3px red;
border-spacing:0; …Run Code Online (Sandbox Code Playgroud)作为一名开发人员,我每天都参与编写大量的数学代码,并且我想在C#语言中添加很少的语法糖来简化代码编写和审阅.
我已经读到这个线程,这等一个可能的解决方案,并只是想知道往哪个方向最好了多少努力,可能只占到解决以下三个问题语法*.
*:我可以在没有描述语法糖的情况下生存,但如果没有太多的工作和Rube-Goldberg为简单的编译过程设计,那么进一步调查可能会很有趣.
我想写:
[double x, int i] = foo(z);
Run Code Online (Sandbox Code Playgroud)
代替:
double x;
int i;
foo(out x, out i, z);
Run Code Online (Sandbox Code Playgroud)
注意:out首先放置参数并foo像往常一样声明(或使用相同类型的语法).
我想要一些新的一元/二元运算符.不知道如何为这些定义(并且在解析源时不引入歧义似乎相当复杂),无论如何想要有类似的东西:
namespace Foo
{
using binary operator "\" as "MyMath.LeftDivide";
using unary operator "'" as "MyMath.ConjugateTranspose";
public class Test
{
public void Example()
{
var y = x';
var z = x \ y;
}
}
}
Run Code Online (Sandbox Code Playgroud)
代替:
namespace Foo
{
public class Test
{
public …Run Code Online (Sandbox Code Playgroud) 我有一个ItemGroup包含一些文件(我无法控制如何生成此列表):
<ItemGroup>
<AllFiles Include="Assembly1.dll;Assembly1.Tests.dll"/>
<AllFiles Include="Assembly2.dll;Assembly2.Tests.dll"/>
...
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
我想创建第二个ItemGroup(基于第一个)仅持有文件名匹配****.Tests.dll.这是FilteredFiles应为:Assembly1.Tests.dll,Assembly2.Tests.dll,...
到目前为止我试过:
<ItemGroup>
<FilteredFiles Include="@(AllFiles)" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(%(Filename), '\.Tests\.dll'))"/>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用.
PS:我也想要非案例敏感的比赛,但这是另一个问题.
我的问题非常特定于matlab编译器和运行时的神秘面纱.由于只有熟悉matlab运行时API的人才能回答,所以我缩短了很多细节.如果我应该更加冗长,请告诉我.
使用matlab编译器和运行时,我可以调用一个用C#程序的m代码编写的函数.我们说要打电话:
function [result] = foo(n)
%[
result = 0;
for k = 1:n,
pause(1.0); % simulate long processing
result = result + 42;
end
%]
Run Code Online (Sandbox Code Playgroud)
with(在C#代码中的一些dllimports后面的某个地方):
mclFeval(IntPtr inst, string name, IntPtr[] plhs, IntPtr[] prhs)
Run Code Online (Sandbox Code Playgroud)
到目前为止,非常好,我对此没有任何问题(即初始化运行时,加载'.cft'文件,使用.Net类型来回编组MxArray等等)
我想foo用一些cancel和progress回调来调查我的函数的进展:
function [result] = foo(n, cancelCB, progressCB)
%[
if (nargin < 3), progressCB = @(ratio, msg) disp(sprintf('Ratio = %f, Msg = %s', ratio, msg)); end
if (nargin < 2), cancelCB = @() disp('Checking cancel...'); end
result …Run Code Online (Sandbox Code Playgroud) 我有一个本地库,其中包含一些本机ntype,并希望在其中调用一些函数.
我能够为:
foo1(ntype** p) ==> foo1(IntPtr[] p)
Run Code Online (Sandbox Code Playgroud)
但不知道如何做到:
foo1(ntype*[] p) ==> foo1(<???> p)
Run Code Online (Sandbox Code Playgroud)
至少IntPtr[]没有奏效.
编辑
我试图编组的非托管函数是:
extern mxArray* mclCreateSimpleFunctionHandle(mxFunctionPtr fcn);
Run Code Online (Sandbox Code Playgroud)
在哪里mxFunctionPtr:
typedef void(*mxFunctionPtr)(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);
Run Code Online (Sandbox Code Playgroud)
这表示调用以下matlab函数签名:
function [varargout] = callback(varargins)
%[
%% Do callback code %%
%]
Run Code Online (Sandbox Code Playgroud)
显然,从我的期望来看,这个函数指针应该为我提供了2个列表mxArray*:
目前,从我所做的测试中,它只返回首创mxArray*的plhs并prhs表
在.NET中使用带有[unsafe]属性的指针时,必须使用/unsafe选项将代码标记为不安全csc.
但是当我使用PInvoke时会发生什么,对我而言,编译程序集似乎都被认为是安全的托管代码,而它可能包含潜在的安全问题,对吧?
注意:这既糟糕又好,因为它是一种使用快速指针操作而不必将程序集标记为的方法/unsafe.
例如
extern "C" __declspec(dllexport) void foo(double* samples)
{
*samples = 42.0;
}
Run Code Online (Sandbox Code Playgroud)
被称为:
[DllImport("native.dll")]
static extern void foo(double[] samples);
Run Code Online (Sandbox Code Playgroud)
或者更明确地(这是默认的编组):
[DllImport("native.dll")]
static extern void foo([MarshalAs(UnmanagedType.LPArray)] double[] samples);
Run Code Online (Sandbox Code Playgroud) 我想将一个数字转换为小数点右边最多 15位的字符串.通过顶多我的意思是,如果最后的数字是全零是没用的,打印出来.
例如:
sprintf('%.15f', 3.0001)
==> '3.000100000000000'
Run Code Online (Sandbox Code Playgroud)
到目前为止一切都很好,但是这里所有的尾随数字都是零,我会更喜欢:
==> '3.0001'
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法来使用sprintf格式说明符,或者我应该手动后处理输出以删除尾随零?
注意:我正在使用matlab,以防有任何其他替代方案sprintf.
我需要在数组中找到最小值和最大值(不考虑此数组中可能的NaN值).
这很容易使用double,但是这些FindMin和FindMax函数必须使用泛型类型.
我试图用这种方式测试通用 NaN:
bool isNaN<T>(T value) where T : IEquatable<T>
{
return !value.Equals(value);
}
Run Code Online (Sandbox Code Playgroud)
但是Equals回来true了double.NaN!! !!
我现在有这样的解决方法:
bool isNaN<T>(T value) where T : IEquatable<T>
{
var d = value as double?;
if (d.HasValue) { return double.IsNaN(d.Value); }
return !value.Equals(value);
}
Run Code Online (Sandbox Code Playgroud)
我的问题更多的是理解为什么第一个解决方案不起作用,这是一个错误吗?
你可以在这里找到小的测试代码
为了删除任何填充或边距,我创建了一个基本的html页面,其中包含一个表格,其高度应为297毫米(A4纸张高度):
<!DOCTYPE html>
<html>
<head>
<style>
body
{
padding: 0; /* Padding for content */
margin: 0 auto; /* Margin from container */
}
table
{
padding: 2.5mm 5mm; /* Padding for content */
margin:0; /* Margin from container */
width:100%;
border-spacing:0;
background-color:yellow;
height:297mm;
}
</style>
</head>
<body>
<table>
<tr style="height:3%"><td style="background-color:RGB(235, 105, 11)">1</td></tr>
<tr style="height:30%"><td style="background-color:RGB(47,52,57)">2</td></tr>
<tr style="height:17%"><td style="background-color:RGB(94,98,102)">3</td></tr>
<tr style="height:auto"><td style="background-color:RGB(255,255,255)">4</td></tr>
<tr style="height:13%"><td style="background-color:RGB(47,52,57)">5</td></tr>
</table>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
我正在尝试使用wkhtml2pdf实用程序以A4 PDF格式呈现此内容(再次处理删除任何边距和/或填充:
wkhtmltopdf.exe --page-size A4 -L 0 -R 0 …Run Code Online (Sandbox Code Playgroud) 介绍
我TextBox在视图中有两个,每个绑定到我的视图模型(Property1,Property2)中的一些属性.
TextBox或者在某些布尔值和属性上启用,IDataErrorInfo在视图模型中使用视图中的某些样式进行验证.
问题
我希望禁用项目时禁用验证样式.
NB1:目前,我发现的解决方案是直接在视图模型中更改验证方案,但这需要通知属性更改以强制视图重新读取IDataErrorInfo(虽然属性没有真正改变,只有选择器.. .)
NB2:我的问题是非常接近此一个,但描述和解决方案都太复杂,对我来说,真的明白了吧.
伪代码
<UserControl
<UserControl.Resources>
<Style TargetType="{x:Type Control}" x:Key="ControlValidationStyle">
...
</Style>
</UserControl.Resources>
...
<TextBox
Text="{Binding Property1,
ValidatesOnDataErrors=True,
UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding IsMode1}"
Style="{StaticResource ControlValidationStyle}"
/>
<TextBox
Text="{Binding Property2,
ValidatesOnDataErrors=True,
UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding IsMode1,
Converter={StaticResource BoolInverse}}"
Style="{StaticResource ControlValidationStyle}"
/>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
ControlValidationStyle
<Style TargetType="{x:Type Control}" x:Key="ControlValidationStyle">
<Style.Resources>
<Style TargetType="ToolTip">
<Setter Property="Background" Value="Tomato" />
<Setter Property="BorderBrush" Value="Red" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="Foreground" Value="white" />
</Style> …Run Code Online (Sandbox Code Playgroud) 为了便于记录,我想展示各种球坐标系,这些坐标系可用于描述球体上的位置(即位置可以描述为xyz坐标或翻转方位角,俯仰方位角或仰角-方位角过大等)。
我没有在.net上找到清晰的插图,尤其是对于非常规惯例,我想使用matlab来创建简单的插图,例如以下示例(翻转角度系统),imao易于理解:

无论如何,我想知道如何创建弯曲的箭头以显示角度方向(上图中的phi / theta箭头)。可以使用quiver3绘制直线向量。我尝试阅读有关内容stream3,但未明白用法。我想要简单的东西:
function [h] = CreateCurvedArrow(startXYZ, endXYZ)
%[
% Draw curved-line in the plane defined by
% vectors 'Origin->StartXYZ' and 'Origin->EndXYZ'
% going from 'StartXYZ' to 'EndXYZ'
%]
Run Code Online (Sandbox Code Playgroud)
我希望有一些简单的方法可以完成,否则我将使用线段来解决。