filename = 'lowshiyan.xlsx'; sheet = 1; [num,txt,raw] = xlsread(filename, sheet); % 添加标签 G = num(:,1); P = num(:,2); T = num(:,3); M = num(:,4); F = num(:,5); Ta = num(:,6); num_images = size(num, 1); image_size = [10, 10]; data_images = zeros([image_size, num_images]); for k = 1:num_images num_elements = numel(num(k,1:5)); num_rows = ceil(num_elements/image_size(1)); image_matrix = reshape(num(k,1:5), num_rows, [])'; % 转置后再reshape resized_image_matrix = imresize([image_matrix, zeros(5, 1)], [10, 2]); % 在右边添加空列将大小从5x1扩展到5x2 resized_image_matrix = resized_image_matrix(:, 1:end-1); % 删除添加的空列 Ta_matrix = Ta(k); % 取第六列数据作为输出数据 image_10by10 = imresize(resized_image_matrix, [10, 10]); % 将大小调整为10x10 data_images(:,:,k) = mat2gray(image_10by10); Ta_images(k) = Ta_matrix; % 存储输出数据 end % 保存输入数据 if ~exist('input_images', 'dir') mkdir('input_images'); % 创建新的文件夹用于存储图像 end for k = 1:num_images input_filename = sprintf('input_images/%d.jpg', k); imwrite(data_images(:,:,k), input_filename, 'jpg'); end % 保存输出数据 if ~exist('output_data', 'dir') mkdir('output_data') % 创建新的文件夹用于存储输出数据 end for k = 1:num_images output_filename = sprintf('output_data/%d.txt', k); dlmwrite(output_filename, Ta_images(k), 'precision', '%.6f'); end % 创建ImageDatastore对象 imds = imageDatastore('input_images', 'FileExtensions', '.jpg', 'LabelSource', 'foldernames'); imds.ReadFcn = @(filename)imresize(imread(filename), [32, 32]); % 调整图像大小为32x32 % 添加输出数据 outputds = tabularTextDatastore('output_data/*.txt', 'ReadVariableNames', false); imds = combine(imds, outputds); % 划分训练集和测试集 [trainImds, testImds] = splitEachLabel(imds, 0.8, 'randomized');检查对函数 'splitEachLabel' 的调用中是否存在不正确的参数数据类型或缺少参数。怎么修改,请给出修改后代码
时间: 2024-01-11 17:03:15 浏览: 86
matlab基础xlsread.pdf
修改后的代码如下:
```
filename = 'lowshiyan.xlsx';
sheet = 1;
[num,txt,raw] = xlsread(filename, sheet);
% 添加标签
G = num(:,1);
P = num(:,2);
T = num(:,3);
M = num(:,4);
F = num(:,5);
Ta = num(:,6);
num_images = size(num, 1);
image_size = [10, 10];
data_images = zeros([image_size, num_images]);
for k = 1:num_images
num_elements = numel(num(k,1:5));
num_rows = ceil(num_elements/image_size(1));
image_matrix = reshape(num(k,1:5), num_rows, [])'; % 转置后再reshape
resized_image_matrix = imresize([image_matrix, zeros(5, 1)], [10, 2]); % 在右边添加空列将大小从5x1扩展到5x2
resized_image_matrix = resized_image_matrix(:, 1:end-1); % 删除添加的空列
Ta_matrix = Ta(k); % 取第六列数据作为输出数据
image_10by10 = imresize(resized_image_matrix, [10, 10]); % 将大小调整为10x10
data_images(:,:,k) = mat2gray(image_10by10);
Ta_images(k) = Ta_matrix; % 存储输出数据
end
% 保存输入数据
if ~exist('input_images', 'dir')
mkdir('input_images'); % 创建新的文件夹用于存储图像
end
for k = 1:num_images
input_filename = sprintf('input_images/%d.jpg', k);
imwrite(data_images(:,:,k), input_filename, 'jpg');
end
% 保存输出数据
if ~exist('output_data', 'dir')
mkdir('output_data') % 创建新的文件夹用于存储输出数据
end
for k = 1:num_images
output_filename = sprintf('output_data/%d.txt', k);
dlmwrite(output_filename, Ta_images(k), 'precision', '%.6f');
end
% 创建ImageDatastore对象
imds = imageDatastore('input_images', 'FileExtensions', '.jpg', 'LabelSource', 'foldernames');
imds.ReadFcn = @(filename)imresize(imread(filename), [32, 32]); % 调整图像大小为32x32
% 添加输出数据
outputds = tabularTextDatastore('output_data/*.txt', 'ReadVariableNames', false);
outputds.SelectedVariableNames = 1;
imds = combine(imds, outputds);
% 划分训练集和测试集
[trainImds, testImds] = splitEachLabel(imds, 0.8, 'random');
```
阅读全文