Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab uitable中特定单元格数据着色的奇怪符号_Matlab_User Interface_Colors_Symbols_Matlab Uitable - Fatal编程技术网

Matlab uitable中特定单元格数据着色的奇怪符号

Matlab uitable中特定单元格数据着色的奇怪符号,matlab,user-interface,colors,symbols,matlab-uitable,Matlab,User Interface,Colors,Symbols,Matlab Uitable,我在GUI中为表的特定行着色时提到过,但是,我得到一些奇怪的符号,而不是这些行中的实际数字,如下所示: 这是我用来着色的代码行: DataTable = [num2cell(handles.zRaw), num2cell(handles.pRaw), num2cell(handles.zMob),... num2cell(handles.PressGrubbs), num2cell(handles.PressRosner), handles.OutlCheckGRubb

我在GUI中为表的特定行着色时提到过,但是,我得到一些奇怪的符号,而不是这些行中的实际数字,如下所示:

这是我用来着色的代码行:

DataTable = [num2cell(handles.zRaw), num2cell(handles.pRaw), num2cell(handles.zMob),...
            num2cell(handles.PressGrubbs), num2cell(handles.PressRosner), handles.OutlCheckGRubbs,...
            handles.OutlCheckRosner, num2cell(handles.iZones), num2cell(handles.iExcessPress)];

        %# Use HTML to style these cells
        n = 1:size(DataTable, 2);
        DataTable(idx, n) = strcat('<html><span style="color: #FF0000; font-weight: bold;">',...
            DataTable(idx, n));
DataTable=[num2cell(handles.zRaw)、num2cell(handles.pRaw)、num2cell(handles.zMob),。。。
num2cell(handles.PressGrubbs)、num2cell(handles.PressRosner)、handles.outlCheckRubbs、,。。。
handles.OutlCheckRosner、num2cell(handles.iZones)、num2cell(handles.iExcessPress)];
%#使用HTML设置这些单元格的样式
n=1:大小(数据表,2);
数据表(idx,n)=strcat(“”,。。。
数据表(idx,n));
此外,我还收到以下警告:

警告:超出范围或非整数值在过程中被截断 转换为字符

在第55个单元格中


在上面的
DataTable
中,变量
句柄。outlcheckrubbs
句柄。OutlCheckRosner
是字符串数组。

问题在于您的表(单元格数组)同时包含数字和字符串数据。当您使用strcat时,它将其所有输入视为字符串,这意味着数字数据将被截断并视为ASCII/Unicode码点。例如:

%# note that double('d')==100
>> strcat(100.6,'aaa')
ans =
daaa
您看到的警告是因为MATLAB实际上只支持前2^16个字符的代码点(UTF-16/UCS-2的BMP平面):

然后,您应该首先将数字转换为字符串:

>> strcat(num2str(100), 'a')
ans =
100a
%# data columns you have. Some are numeric, others are strings
col1 = rand(10,1);
col2 = repmat({'ok'},10,1);
col3 = randi(100, 10,1);

%# combine into a table cell-array (all strings)
convert = @(x) strtrim(cellstr(num2str(x)));
table = [convert(col1) col2 convert(col3)];

%# apply custom formatting to some rows
idx = rand(10,1)>0.7;
table(idx,:) = strcat('<html><span style="color: red;">', table(idx,:));

%# show uitable
uitable('Data',table)

编辑: 下面是一个类似于您的代码的示例。请注意,必须首先将数字列转换为字符串:

>> strcat(num2str(100), 'a')
ans =
100a
%# data columns you have. Some are numeric, others are strings
col1 = rand(10,1);
col2 = repmat({'ok'},10,1);
col3 = randi(100, 10,1);

%# combine into a table cell-array (all strings)
convert = @(x) strtrim(cellstr(num2str(x)));
table = [convert(col1) col2 convert(col3)];

%# apply custom formatting to some rows
idx = rand(10,1)>0.7;
table(idx,:) = strcat('<html><span style="color: red;">', table(idx,:));

%# show uitable
uitable('Data',table)

为简单起见,我假设4种颜色与4行匹配。

我使用
num2str
将7个双数组转换为字符串数组(而不是所示的单元格数组),使用
char
将2个单元格数组转换为字符串数组。但是,从数字转换的7个数组(
50 x 1
)的大小与从单元格转换的用于字符串连接的其他2个数组(
50 x 7
)的大小不兼容;因此,我得到了一个错误
下标赋值维度不匹配。
知道如何使维度一致吗?@product:我添加了一个示例,演示如何在将数值列转换为stringsIf而不是红色时连接列。我想指定4种不同的颜色(例如
clr={r',g',b',m'}
)对于4个已定义的索引(例如,
idx=[1,4,5,9]
),我如何在html中高效地定义这些颜色代码而不使用循环?@product:请参阅我的编辑。如果您的颜色数与行数不同,则必须编写一些代码来“循环”颜色。出于某种原因,我不得不使用循环来提取着色所需的索引,因此我使用了以下方法:
clrHTML={'red','blue','green','magenta','yellow','cyan};对于iZ=1:max(handles.iZones)idx=(handles.iZones==iZ);DataTable(idx,:)=strcat([''),…DataTable(idx,:);结束
…谢谢!