MATLAB Answers

0

Subscripting into an mxArray is not supported

Asked by basavsagar on 19 Mar 2014
Latest activity Commented on by Ryan Livingston on 8 Nov 2018
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

  0 Comments

Sign in to comment.

Tags

Products

1 Answer

Answer by Ryan Livingston on 20 Mar 2014
 Accepted Answer

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:

  6 Comments

If you run class(operspec(plant_model)), what does that return. Is that an object or a struct?
Similarly, what does class(StructOpspec()) return?
class(operspec(plant_mdl))
ans= 'opcond.OperatingSpec'
class(StructOpspec())
ans= 'struct'
Like I said StructOpspec() is my own function which constructs a structure similar to operspec()'s output.
Thanks for the info. StructOpspec needs to return the same type as operspec, namely opcond.OperatingSpec. Using a struc for an example output of an extrinsic function that returns an object isn't supported.
An alternative can be to move all of the code using that object to a MATLAB function that you call as an extrinsic. That function would accept and return values that are not objects thereby avoiding this class of issue.

Sign in to comment.