Subscripting into an mxArray is not supported

10 次查看(过去 30 天)
hi guys i am trying to convert my matlab code to c++,in this process i am getting an error saying "Subscripting into an mxArray is not supported" in the below code
1function wordtocharacter() %#codegen
2coder.extrinsic('uigetfile');
3coder.extrinsic('strcat');
4coder.extrinsic('imread');
5coder.extrinsic('imshow');
6coder.extrinsic('im2bw');
7coder.extrinsic('fprintf');
8coder.extrinsic('sprintf');
9coder.extrinsic('fullfile');
10coder.extrinsic('imwrite');
11%coder.extrinsic('BW');
12coder.extrinsic('figure');
13coder.extrinsic('delete');
14coder.extrinsic('im2double');
15
16%clc;
17%clear all;
18%close all;
19[fn fp] = uigetfile('*.bmp');
20%mkdir(fn);
21fn=strcat(fp,fn);
22I=imread(fn);
23%fn=strcat(fn,'\');
24%BW=0;
25BW=im2bw(I,0.4);
26%figure,
27imshow(BW);
28I2=im2double(BW);
29height=0;
30width=0;
31[height, width]=size(BW);
32isStart=1;
33boundary=[];
34isIn=0;
35start=0;
36factor=0.1;
37j=1;
38for j=1:width
39 hasWhite=0;
40 for i=1+round(factor*height):round(height*(1-factor))
41 if(I2(i,j)==1)
42 if(isStart==1)
43 isStart=0;
44 start=j;
45 end
46 hasWhite=1;
47 isIn=1;
48 break;
49 end
50 end
51 if(hasWhite==0)
52 if(isIn)
53 if(j-start>height/4)
54 isStart=1;
55 isIn=0;
56 boundary=[boundary start j];
57 else
58 isStart=0;
59 start=j;
60 end
61 end
62 end
63end
64num=size(boundary)/2;
65fprintf('the character is %d \n', num(2));
66%mkdir('C:\Users\basavsagar\Desktop\segcode');
67delete('E:\seg\*.JPG');
68
69for i=1:num(2)
70 f1=I2(1:height, boundary(2*i-1):boundary(2*i));
71 figure,imshow( f1);
72
73 file_name=sprintf('%d.jpg',i); % assuming you are saving image as a .jpg
74 fullFileName = fullfile('E:\seg', file_name);
75 imwrite(f1, fullFileName); % or something like this, however you choose to save your image
76end
77 %baseFileName = sprintf('image %d.png', i);
78 %fullFileName = fullfile(output, baseFileName);
79 % imwrite('i1', fullFileName);
80 % fn=strcat(fn,'figure',num2str(i),'.bmp');
81 % imwrite(f1,fn,'bmp');
82end
these are the errors i am getting
(Line no)
1 wordtocharacter 41 Subscripting into an mxArray is not supported.
2 wordtocharacter 70 Subscripting into an mxArray is not supported.
3 wordtocharacter 71 Undefined function or variable 'f1'. The first assignment to a local variable determines its class.
4 wordtocharacter 75 Undefined function or variable 'f1'. The first assignment to a local variable determines its

采纳的回答

Ryan Livingston
Ryan Livingston 2014-3-20
I2 is assigned as the output of im2double which is an extrinsic call. When doing that you need to assign I2 prior to the extrinsic call to give the code generation software information about its size, type and so on:
I2 = zeros(12,14);
I2 = im2double(BW);
supposing that I2 would be 12-by-14.
This answer covers it in more detail:
And some documentation on this:
  9 个评论
Fakhreddin Amirhosseini
Hi, Thanks for your support.
I'm facing a simular problem.
What if the output of the extrinsic function is not an integer or double but rather an object. How can I predefine that variable?
I'm using Bluetooth function as an extrinsic function. The output of this function is a bluethooth object and the only whay to define a bluetooth object is to call the bluetooth function itself. So my problem is that how can I define a bluetooth object so that the code generation software can
Max Weigert
Max Weigert 2020-8-6
I'm facing a similar problem, where I can't predefine an object, as it has the same name, as the function, which has the given object as output.
Have you found a solution for it already?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Configure Simulation Conditions 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by