matlab - imwrite 在 Matlab 中给出不一致的错误

标签 matlab strcat imread

我写了一个代码来清理和打印多张图片,

data_1=csvread(data)
for h=1:30
    im_old=imread(strcat('catches\image_generator (',int2str(h),').png'));
    im_bw=func_bw(im_old);
    im_2=func_clean_tr(im_bw);
    [im_3a,im_3b]=edge_trial(im_2);
    da=data_1{h,2};
    name=strcat('trrr\',da,'trial.png');
    imwrite(im_3b,strcat('trrr\',int2str(h),'trial.png'));
end

有一个特别的问题。当参数为:

imwrite(im_3b,strcat('trrr\',int2str(h),'trial.png'));

但是当我给出参数时它不会工作:

imwrite(im_3b,strcat('trrr\',da,'trial.png'));

我交叉检查 da 是一个 1x1 字符串并且 strcat('trrr\',da,'trial.png') 也是一个 1x1 字符串。 显示的错误是:

Error using imwrite>parse_inputs (line 510)

A filename must be supplied.

不知道为什么 imwrite 会以不同的方式处理两个字符串...

Edit1:我的 data_1 是这样写的: 1、X55N3 2、PQZXS 3、HDDS3... 另外,da=data_1{h,2} 的值;是“X55N3”

最佳答案

MATLAB 仍然有点 transitioning to the new string class .传统上,MATLAB 一直使用 char需要字符串的数组。他们介绍了string R2016b 中的类,还没有更新所有工具箱中的所有函数,还需要 string他们过去常去的地方 char数组。

我正在使用 R2017a,在使用 imread 时看到这个用一个字符串:

>> imread("cameraman.tif");
Error using imread>parse_inputs (line 450)
The file name or URL argument must be a character vector.

Error in imread (line 322)
[filename, fmt_s, extraArgs, was_cached_fmt_used] = parse_inputs(cached_fmt, varargin{:});

但是,这是可行的:

>> imread(char("cameraman.tif"));

因此您的解决方案是转换 string进入char数组:

imwrite(im_3b,char(strcat('trrr\',da,'trial.png')));

或:

imwrite(im_3b,strcat('trrr\',char(da),'trial.png'));

关于matlab - imwrite 在 Matlab 中给出不一致的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48719445/

相关文章:

r - R中代码质量的量化

matlab - 神经网络训练matlab parfor问题

c - 将元素 append 到C中的字符串数组中

c++ - OpenCV : undefined reference to imread()

matlab - 在等待栏中禁用 TeX 解释消息

matlab - MATLAB 上的 CUDA 循环

c++ - 在 C++ 中连接 C 字符串的更优雅的方法?

C: "zsh: abort"错误

c++ - openCV imread 限制大或巨大的图像 Mat bug #3258

python - 从多 channel 图像中提取 channel 名称