Convert character array to string in MATLAB

Matlab提取特征值是经常要读取多个图片文件,把文件名保存在数组中后再读取会出错。从stackoverflow中找到如下解决方法:

I‘ve a M by N matrix, each cell contains a character array, that is an image path. How can I use it to read image? It should be string.

It‘s what I try to do:

imread(fl(1,1));
??? Error using ==> imread>parse_inputs at 491
The filename or url argument must be a string.

Error in ==> imread at 336
[filename, fmt_s, extraArgs, msg] = parse_inputs(varargin{:});

Replace fl(1,1) with fl{1,1}. You access the contents of a cell-array with {}. You access the cell element itself with ().

Since imread expects a string and not a cell element, it throws that error.

 
时间: 2024-10-10 14:15:30

Convert character array to string in MATLAB的相关文章

Matlab一个错误引发的血案:??? Error using ==> str2num Requires string or character array input.

Matlab总遇到一些神奇的问题,让人摸不着头脑.昨天编写程序的时候遇到一个让我十分火大的问题,也是自己的matlab基础不好吧. 先描述一下问题,再GUI界面有个listbox,Tag属性是’listbox1’,里面是这样的数据,我的目的是要把这些数据转换成数值类型的矩阵: list_string = get(handles.listbox1,'string') data=str2num((list_string)); 使用上面两行代码进行转换却异常出错了!看后台的错误描述如下: ??? Er

iconv() : Detected an illegal character in input string 报错解决(抄的)

HP传给JS字符串用ecsape转换加到url里,又用PHP接收,再用网上找的unscape函数转换一下,这样得到的字符串是UTF-8的,但我需要的是GB2312,于是用iconv转换 开始是这样用的 $str = iconv('UTF-8', 'GB2312', unescape(isset($_GET['str'])? $_GET['str']:'')); 上线后报一堆这样的错:iconv() : Detected an illegal character in input string 考

Convert CString to ANSI string in UNICODE projects

Convert CString to ANSI string in UNICODE projects Quick Answer: use an intermediate CStringA. Normally, this is not something that should be done. *It is technically unreliable, unless you can guarantee that the source CString to be converted does n

golang array, slice, string笔记

本来想写一篇关于golang io的笔记,但是在学习io之前必须了解array, slice, string概念,因此将在下篇写golang io. array: 数组的长度是该数组类型的一部分,例如var buffer [256]byte 的类型是[256]byte, len(buffer)总是返回256. slice: 一个slice描述一个数组中连续的一部分,例如var slice = buffer[100:250].slice也可以从slice产生,如var slice2 = slice

LeetCode OJ - Convert Sorted Array/List to Binary Search Tree

虚函数使用的时机 为什么虚函数不总是适用? 1. 虚函数有事会带来很大的消耗: 2. 虚函数不总是提供所需的行为: 3. 当我们不考虑继承当前类时,不必使用虚函数. 必须使用虚函数的情况: 1. 当你想删除一个表面上指向基类对象,实际却是指向派生类对象的指针,就需要虚析构函数. LeetCode OJ - Convert Sorted Array/List to Binary Search Tree,布布扣,bubuko.com LeetCode OJ - Convert Sorted Arra

Leetcode-387 First Unique Character in a String

#387.   First Unique Character in a String Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: You m

leetcode 108 Convert Sorted Array to Binary Search Tree

题目连接 https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ Convert Sorted Array to Binary Search Tree Description Given an array where elements are sorted in ascending order, convert it to a height balanced BST. /** * Definition f

39.1: Convert Sorted Array to Binary Search Tree

/************************************************************************/            /*       39.1:  Convert Sorted Array to Binary Search Tree                               */            /************************************************************

Convert Sorted Array to Binary Search Tree & Convert Sorted List to Binary Search Tree

Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 方法:将有序数组转为平衡二叉树,我们知道平衡二叉树的中序遍历是有序数组,而且“中间”的元素可以作为根节点,那么构建树的时候,找出中间元素,构造根元素,然后继续重复上面的方法,构造左子树和右子树.代码如下: 1 /**