Error with ismember in a loop for
显示 更早的评论
tickers='tickers.txt';
price=hist_stock_data('09032015','09032016',tickers);
prices=zeros(size(price(1, 1).AdjClose,1),size(price,2));
for t=1:size(price,2);
prices(:,t)= price(1, t).AdjClose;
end
for t=1:size(price,2);
nomes{1,t}=price(1, t).Ticker;
end
couple=[nomes(myrow)',nomes(mycol)'];
cl=num2cell(prices);
ff=[nomes;cl];
for ii=1:size(couple,1);
looking_up=couple(ii,:);
[tf, coldix]=ismember(looking_up,ff(ii,:));
prices=ff(:,coldix(tf));
prices=prices(2:end,:);
prices=cell2mat(prices);
x(ii)=prices(:,2);
y(ii)=prices(:,1);
end
give me the following error: "Input A of class cell and input B of class cell must be cell arrays of strings, unless one is a string".
回答(1 个)
Jan
2016-4-11
As the error message tells you, ismember operates on cells only, if they are cell strings. In your care the data are not cell strings. You can find out, what they are instead:
dbstop if all error
Then runs the code again. When Matlab stops at the error, type this in the command window:
class(looking_up)
class(looking_up{1})
class(ff)
class(ff{1})
Due to the absence of comments, we cannot guess what you want to achieve.
类别
在 帮助中心 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!