Quantcast
Channel: MATLAB Central Newsreader - tag:"find"
Viewing all articles
Browse latest Browse all 55

Re: Too Many Inputs using Finf Function

$
0
0
On 04/17/2017 7:21 PM, Lilith Nick wrote:
> SGandCP={'Material' 'Specific Gravity (SG) [ - ]' 'Specific Heat (CP)
> [J/(g K)]'
> 'Aluminum' 2.70000000000000 0.897000000000000
> 'Copper' 8.96000000000000 0.385000000000000
> 'Lead' 11.3400000000000 0.129000000000000
> 'Nylon' 1.15000000000000 1.70000000000000
> 'Polypropylene' 0.946000000000000 1.92000000000000
> 'Steel' 7.95000000000000 0.477000000000000
> 'Zinc' 7.13000000000000 0.388000000000000}
>
> [r,c]=SGandCP(find(SGandCP{:,1},'Steel'),2);
>
> returns the error
> "Too many input arguments"
>
> How do I fix this?

 >> SGandCP(ismember(char(SGandCP{:,1}),'Steel','rows'),2)
ans =
     [7.9500]
 >>

Since your variable is a cell array, the expansion from the colon
subscript returns a comma-separated list, not a single array. Since
it's text and not same length, [] aren't sufficient to catenate the
elements, hence CHAR() to do that job.

Alternatively,

 >> idx=find(~cellfun(@isempty,strfind(SGandCP(:,1),'Steel')))
idx =
      7
 >>

Cell arrays are handy for disparate data types, but a
pit(proverbial)a(ppendage) to work with...

I'd suggest there would be good spot for a table that would make lookups
much simpler.

--

Viewing all articles
Browse latest Browse all 55

Trending Articles