matlab readtable没有字段,引用了不存在的字段问题。

% --- Executes on button press in Loadbutton.

function Loadbutton_Callback(hObject, eventdata, handles)

% hObject    handle to Loadbutton (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

[filename,pathname]=uigetfile({'*.*';'*.bmp';'*.jpg';'*.tif';'*.jpg'},'选择图像');

if isequal(filename,0)||isequal(pathname,0)

errordlg('您还没有选取图片!!','温馨提示');%如果没有输入,则创建错误对话框

return;

end

image=[pathname,filename];%合成路径+文件名

im=imread(image);%读取图像

set(handles.axes1,'HandleVisibility','ON');%打开坐标,方便操作

axes(handles.axes1);%使用图像,操作在坐标1

imshow(im);%在坐标axes1显示原图像

title('原始图像');

RGB = imread(image);

handles.RGB = RGB;

handles.RGB2 = RGB;

handles.fileLoaded = 1;

handles.fileLoaded2 = 0;

im=double(im);

avg_im=mean(im);%计算均值

avg_imc=num2str(avg_im);%转换数据类型(以下同理)

var_im=var(im(:));

var_imc=num2str(var_im);

max_im=max(im(:));

max_imc=num2str(max_im);

min_im=min(im(:));

min_imc=num2str(min_im);

set(handles.text2,'String','均值');

set(handles.text3,'String','方差');

set(handles.text4,'String','最大值');

set(handles.text5,'String','最小值');

set(handles.mean_staticText,'String',avg_imc);

set(handles.var_staticText,'String',var_imc);

set(handles.maximum_staticText,'String',max_imc);

set(handles.minimum_staticText,'String',min_imc);

GUIdata(hObject, handles);

% --- Executes during object creation, after setting all properties.

function text2_CreateFcn(hObject, eventdata, handles)

% hObject    handle to text2 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% --- Executes on button press in Conv.

function Conv_Callback(hObject, eventdata, handles)

% hObject    handle to Conv (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded == 1)

Gray=rgb2gray(handles.RGB);

axes(handles.axes1);imshow(Gray);title('原灰度图像');

A=double(Gray);

H=[1 0 -1;1 0 -1;1 0 -1];

Conv=conv2(A,H,'same');

axes(handles.axes2);imshow(Conv);title('滤波处理后');

GUIdata(hObject, handles);

else

H = msgbox('No primary file has been loaded!','Error','error');

end

% --- Executes on button press in Color2Gray.

function Color2Gray_Callback(hObject, eventdata, handles)

% hObject    handle to Color2Gray (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded==1)

Gray = rgb2gray(handles.RGB);

axes(handles.axes2); imshow(Gray);title('灰度图像');

handles.fileLoaded2 = 1;

set(handles.mean_staticText,'String',' ');

set(handles.text2,'String',' ');

set(handles.var_staticText,'String',' ');

set(handles.text3,'String',' ');

set(handles.maximum_staticText,'String',' ');

set(handles.text4,'String',' ');

set(handles.minimum_staticText,'String',' ');

set(handles.text5,'String',' ');

GUIdata(hObject,handles);

end

% --- Executes on button press in Hist.

function Hist_Callback(hObject, eventdata, handles)

% hObject    handle to Hist (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

set(handles.axes1,'Visible','off'); set(handles.axes2,'Visible','off');

set(handles.axeshist1,'Visible','off'); set(handles.axeshist2,'Visible','off');

if (handles.fileLoaded == 1)

Gray = rgb2gray(handles.RGB);

[height,width] = size(Gray);

axes(handles.axes1); imshow(Gray);title('原灰度图');

axes(handles.axeshist1); imhist(Gray);

s = zeros(1,256);%统计各灰度数目,共256个灰度级

for i = 1:height

for j = 1: width

s(Gray(i,j) + 1) = s(Gray(i,j) + 1) + 1;%对应灰度值像素点数量增加一

end

end

%计算灰度分布密度

p = zeros(1,256);

for i = 1:256

p(i) = s(i) / (height * width * 1.0);

end

%计算灰度分布密度

p = zeros(1,256);

for i = 1:256

p(i) = s(i) / (height * width * 1.0);

end

%计算累计直方图分布

c = zeros(1,256);

c(1) = p(1);

for i = 2:256

c(i) = c(i - 1) + p(i);

end

%累计分布取整,将其数值归一化为1~256

c = uint8(255 .* c + 0.5);

%对图像进行均衡化

for i = 1:height

for j = 1: width

Gray(i,j) = c(Gray(i,j)+1);

end

end

axes(handles.axes2); imshow(Gray);title('直方图均衡化');

axes(handles.axeshist2); imhist(Gray);

GUIdata(hObject,handles);

end

% --- Executes on button press in Log.

function Log_Callback(hObject, eventdata, handles)

% hObject    handle to Log (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

set(handles.axes1,'Visible','off'); set(handles.axes2,'Visible','off');

set(handles.axeshist1,'Visible','off'); set(handles.axeshist2,'Visible','off');

if (handles.fileLoaded == 1)

Gray = rgb2gray(handles.RGB);

axes(handles.axes1); imshow(Gray);title('原灰度图');

Gray=double(Gray);

newpic=log(1+Gray);

axes(handles.axes2);

imshow(newpic,[]);

title('对数变换后');

GUIdata(hObject,handles);

end

% --- Executes on button press in pushbutton5.

function pushbutton5_Callback(hObject, eventdata, handles)

% hObject    handle to pushbutton5 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% --- Executes during object creation, after setting all properties.

function mean_staticText_CreateFcn(hObject, eventdata, handles)

% hObject    handle to mean_staticText (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% --- Executes during object creation, after setting all properties.

function axes3_CreateFcn(hObject, eventdata, handles)

% hObject    handle to axes3 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes3

以上代码。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 可以使用table2array函数将matlabtable转换成double类型的数组。例如: T = table([1;2;3],[4;5;6],'VariableNames',{'Var1','Var2'}); A = table2array(T); D = double(A); 其,T是一个包含两列数据的table,A是将T转换成数组后得到的结果,D是将A转换成double类型的数组。 ### 回答2: 在MATLABtable 是一种非常强大的数据类型,可以方便地存储和管理多维表格数据。然而,在某些情况下,我们需要将 table 转换成 double 类型,对于这种需求,MATLAB 提供了多种方法,以下将逐一介绍。 1.使用 table2array 函数将 table 转换成数组 table2array 函数可以将 table 转换成数组,该数组的数据类型为 double。示例代码如下: t = readtable('myTable.csv'); d = table2array(t); 上述代码将 myTable.csv 文件的数据读取到 table 变量 t ,并使用 table2array 函数将其转换为数组 d。 2.使用 varfun 函数将 table 转换成包含 double 变量的 table varfun 函数是 table 对象的方法,可以对 table 的每一列应用一个函数,并使用输出作为 table 的新一列。因此,我们可以使用 varfun 函数将 table 转换成包含 double 变量的 table。示例代码如下: t = readtable('myTable.csv'); d = varfun(@double, t); 上述代码将 myTable.csv 文件的数据读取到 table 变量 t ,并使用 varfun 函数将其转换为包含 double 变量的 table d。 3.将 table 的每一列转换成 double 数组,并将这些数组合并成一个大数组 table 对象有一个叫做 table2array 的方法,用于将 table 的每一列转换成数组。因此,我们可以使用这个方法来将 table 转换成 double 数组,并将这些数组合并成一个大数组。示例代码如下: t = readtable('myTable.csv'); d = [table2array(t(:, 1)), table2array(t(:, 2)), table2array(t(:, 3))]; 上述代码将 myTable.csv 文件的数据读取到 table 变量 t ,并将 table 的每一列转换成数组,然后将这些数组按列合并成一个大数组 d。 总之,MATLAB 提供了多种方法将 table 转换成 double 类型,具体选择哪种方法取决于具体问题和数据。 ### 回答3: 要在MATLAB将一个表(table)转换为双精度数组(double)可以使用表的内容函数(contents)和双精度函数(double)结合使用。 首先,使用表的内容函数可以获取表所有的数据,这个函数将返回一个结构体数组。调用示例代码为: ``` tbl = readtable('data.csv'); data = tbl{:,:}; % 使用表的内容函数获取所有数据 ``` 这里‘data.csv’是一个表格文件的路径。 然后,可以使用双精度函数将结构体数组的每个元素转换成双精度格式。调用示例代码为: ``` data_double = double(data); ``` 这个操作将从结构体数组提取出每个字段的数据并将其转换为双精度格式。注意,转换后的双精度数组不再包含表的行和列标签,只有数据本身。 在实际使用,如果表有缺失值(NaN)的情况,转换成双精度数组时会出现错误。一种简单的解决方法是先使用表的ismissing函数将缺失值的位置标记出来,然后使用双精度函数将非缺失值部分转换为双精度格式。 调用示例代码为: ``` tbl = readtable('data.csv'); is_missing = ismissing(tbl); tbl(is_missing) = NaN; data = tbl{:,:}; data(~is_missing) = double(data(~is_missing)); ``` 这个操作先将表缺失值的部分标记为NaN,然后将非缺失值部分转换为双精度格式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值