How to solve Error using delete. Argument must contain a string.

12 visualizzazioni (ultimi 30 giorni)
function [char_out, letter] = projection_profileBeta()
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
%format compact;
%format loose;
global caption;
img_biner =imread('text_document.jpg');
%find the vertical profile
verticalProfile = sum(binaryImage, 2);
% Find dividing lines between the characters.
props = regionprops(verticalProfile == 0, 'Centroid');
%props = regionprops(horizontalProfile <= 1, 'Centroid'); % new modified
xyCentroids = [props.Centroid];
%dividingLines = xyCentroids(1:2:end)
dividingLines = xyCentroids(2:2:end)
% Extract each line.
global hSubplots;
indexSubplot = (1:10);
% indexSubplot2 = (6:10);
for k = 1 : length(dividingLines)-1
thisX = round(dividingLines(k));
nextX = round(dividingLines(k+1));
subplot(20, 10, indexSubplot );
thisLetter = binaryImage(thisX:nextX, :); % line cropping
caption = sprintf('Letter #%d', k);
title(caption, 'FontSize', 8);
indexSubplot = indexSubplot + 10;
%% Cropping Lines into Character
char_out = horizontal_profile(thisLetter);
%% End
pause(0.5) % se we can se every cropping
% indexSubplot = (indexSubplot) + 3;
% indexSubplot2 = (indexSubplot2) + 10;
if k ~= length(dividingLines)-1 % delete hSubplots if k is not euqal to limit loop
delete(hSubplots); % to refresh subplots of characters in the figure 2.
%SECOND FUNCTION to crop each characters from the each lines
function char_crop = horizontal_profile(img_letters)
global caption;
global hSubplots;
h1 = subplot(4, 12, 1:12);
% Find horizontal profile
h2 = subplot(4, 12, 13:24);
horizontalProfile = sum(img_letters, 1);
plot(horizontalProfile, 'b-');
title('Horizontal Profile', 'FontSize', 20);
grid on;
% Find dividing lines between the characters.
props2 = regionprops(horizontalProfile == 0, 'Centroid');
%props = regionprops(horizontalProfile <= 1, 'Centroid'); % new modified
xyCentroids2 = [props2.Centroid];
%dividingLines = xyCentroids(1:2:end)
dividingChar = xyCentroids2(1:2:end);
hSubplots = {};
for kk = 1 : length(dividingChar)-1
thisX2 = round(dividingChar(kk));
nextX2 = round(dividingChar(kk+1));
%h3 = subplot(4, 12, indexSub+kk);
h3 = subplot(4, 12, 24+kk);
thisCharacter = img_letters(:, thisX2:nextX2);
char_crop = padarray(img_out, [1 1], 'both'); % padding the image by 1 on every sides.
char_crop = imresize(char_crop,[42, 24]); % resizing to be 42m x 24n
char_crop = bwmorph(char_crop, 'thin', Inf);%Image Thinning
caption2 = sprintf('Character #%d', kk);
title(caption2,'FontSize', 12);
%collecting all subplots' positions.
hSubplots{kk} = {hSubplots, h3};
% % Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.05, 1, 0.95]);
when i tried this code without separated function , it worked beautifully. but when i separated the code into 2 different function in a m-file, the code gave me error like this:
Error using delete
Argument must contain a string.
Error in projection_profileBETA (line 94)
delete(hSubplots); % to refresh all subplots in the figure 2.
why did it demand a string suddenly on delete parameter ?
thank you
  3 Commenti

Accedi per commentare.

Risposta accettata

Jan il 7 Gen 2019
I guess this is the old problem of using globals: You cannot see, where such variables are changed. A callback of a timer or a GUI can modify it without any chance to see, who is responsible.
Use at least the debugger to find out, what the contents of hSubplots is. Type this in the command window:
dbstop if error
Run your code again and when it stops type:
What do you see? Does this reveal why the value is not accepted by delete?
  13 Commenti
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis il 27 Gen 2019
@ Walter Roberson : i think so sir. I just tought that it was same if i store those vector of grafic handles to cell instead of array, even faster.
Thank you for the info sir. you've helped me a lot

Accedi per commentare.

Più risposte (0)




Community Treasure Hunt

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

Start Hunting!

Translated by