Prev: CRC-32 for IEEE 802.11-2007
Next: ocr matlab
From: Claudia Champagne on 14 Jan 2010 15:36 How can I enter string inputs into a function within a loop? I want to use the function [d,A]=strdist(r,b,krk,cas) in a loop since I have a number of r and b inputs for which I need the distance. The problem is that inputs r and b have to appear in a string form for the function to work: e.g. strdist('MATLAB','MathWorks',2,1) ans = 6 9 However, if these 2 strings ('Matlab' and 'Mathworks') are located in arrays, the function does not work properly as it doesn't read them as strings. For example: r_array = cell array of r (where 'Matlab' is located) b_array = cell array of b (where 'MathWorks' is located) I tried the following : [d,A] = strdist(cellstr(r_array{1,1}), cellstr(b_array{1,1}),2,1) and I get an answer if 1, which is the answer that I get when I enter just about anything as input. How can I tell the function to read my inputs as strings?
From: Andy on 14 Jan 2010 15:46 "Claudia Champagne" <claudia.champagne(a)usherbrooke.ca> wrote in message <hinv5p$6p7$1(a)fred.mathworks.com>... > How can I enter string inputs into a function within a loop? > > I want to use the function [d,A]=strdist(r,b,krk,cas) in a loop since I have a number of r and b inputs for which I need the distance. > > The problem is that inputs r and b have to appear in a string form for the function to work: > e.g. strdist('MATLAB','MathWorks',2,1) > ans = 6 9 > > However, if these 2 strings ('Matlab' and 'Mathworks') are located in arrays, the function does not work properly as it doesn't read them as strings. > > For example: > r_array = cell array of r (where 'Matlab' is located) > b_array = cell array of b (where 'MathWorks' is located) > > I tried the following : > > [d,A] = strdist(cellstr(r_array{1,1}), cellstr(b_array{1,1}),2,1) > > and I get an answer if 1, which is the answer that I get when I enter just about anything as input. > > How can I tell the function to read my inputs as strings? % You could start by not explicitly converting them to cell arrays: [d,A] = strdist(r_array{1,1}, b_array{1,1},2,1)
From: Jan Simon on 14 Jan 2010 16:11 Dear Claudia! > I want to use the function [d,A]=strdist(r,b,krk,cas) in a loop since I have a number of r and b inputs for which I need the distance. > However, if these 2 strings ('Matlab' and 'Mathworks') are located in arrays, the function does not work properly as it doesn't read them as strings. > > r_array = cell array of r (where 'Matlab' is located) > b_array = cell array of b (where 'MathWorks' is located) I cannot follow. Please post valid Matlab commands, because "cell array of b (where 'MathWorks' is located)" is ambiguos. > I tried the following : > [d,A] = strdist(cellstr(r_array{1,1}), cellstr(b_array{1,1}),2,1) > and I get an answer if 1, which is the answer that I get when I enter just about anything as input. It seems to me like you confuse the terms "array", "string" and "cell string". The command CELLSTR creates a cell string, e.g. {'string1'}. A "cell string" is a cell array, which contains strings as elements. Strings are arrays of type CHAR. You've stated, that STRDIST needs strings as input. To get an element of a cell string, reference it with the curly braces and you get string. As far as I understood, your input is something like: r = {'Matlab', 'MattLab', 'MatSchlapp'} b = {'MathWorks', 'TheMathWorks', 'TMW'} Then you can call STRDIST like: for i = 1:length(r) for j = 1:length(b) [d, A] = strdist(r{i}, b{j}, 2, 1) end end But I might be missing the point. Then I please you to paste your Matlab code. Kind regards, Jan
From: Miroslav Balda on 14 Jan 2010 16:40 "Claudia Champagne" <claudia.champagne(a)usherbrooke.ca> wrote in message <hinv7i$afv$1(a)fred.mathworks.com>... > How can I enter string inputs into a function within a loop? > > I want to use the function [d,A]=strdist(r,b,krk,cas) in a loop since I have a number of r and b inputs for which I need the distance. > > The problem is that inputs r and b have to appear in a string form for the function to work: > e.g. strdist('MATLAB','MathWorks',2,1) > ans = 6 9 > > However, if these 2 strings ('Matlab' and 'Mathworks') are located in arrays, the function does not work properly as it doesn't read them as strings. > > For example: > r_array = cell array of r (where 'Matlab' is located) > b_array = cell array of b (where 'MathWorks' is located) > > I tried the following : > > [d,A] = strdist(cellstr(r_array{1,1}), cellstr(b_array{1,1}),2,1) > > and I get an answer if 1, which is the answer that I get when I enter just about anything as input. > > How can I tell the function to read my inputs as strings? Hi, It is necessary to test the input variables, just like: function [d,A] = strdist(a,b,c,d) % STRDIST ...... if ischar(a) r = a; else r = a{:}; end : etc Hope it helps Mira
From: Oleg Komarov on 14 Jan 2010 17:48 "Claudia Champagne" > How can I enter string inputs into a function within a loop? > > I want to use the function [d,A]=strdist(r,b,krk,cas) in a loop since I have a number of r and b inputs for which I need the distance. > > The problem is that inputs r and b have to appear in a string form for the function to work: > e.g. strdist('MATLAB','MathWorks',2,1) > ans = 6 9 > > However, if these 2 strings ('Matlab' and 'Mathworks') are located in arrays, the function does not work properly as it doesn't read them as strings. > > For example: > r_array = cell array of r (where 'Matlab' is located) > b_array = cell array of b (where 'MathWorks' is located) > > I tried the following : > > [d,A] = strdist(cellstr(r_array{1,1}), cellstr(b_array{1,1}),2,1) > > and I get an answer if 1, which is the answer that I get when I enter just about anything as input. > > How can I tell the function to read my inputs as strings? In1 = {'Hi','Hello'}; In2 = {'Bye','GoodBye'}; nIter = numel(In1); if nIter == numel(In2) Out = cell(nIter,2); for n = 1:numel(In1) [Out{nIter,1}, Out{nIter,1}] = strdist(In1{nITer},In2{nITer},2,1); end Oleg
|
Pages: 1 Prev: CRC-32 for IEEE 802.11-2007 Next: ocr matlab |