0

I have large array P which is changing size and values in each iteration. I need to be able to change the title of my output array to match the given iteration, i.e. for bin 1.4 I would like output to be p1.4 or p14.

Can anyone help?

for bin = 1:0.1:2;
    rows = find(DAT(:,27) > bin);
    p{bin} = DAT(rows,:);
end
1
  • fprintf('p%.1f\n', bin); ? Commented Mar 14, 2013 at 14:39

2 Answers 2

4

If I understood you correctly, the code is

for bin = 1:0.1:2;
    rows = find(DAT(:,27) > bin);
    current_p = DAT(rows,:);
    eval(sprintf('p%0.f=current_p;', bin * 10));
end

But why do you need this? Consider use a smarter container like containers.Map:

p = containers.Map('KeyType', 'double', 'ValueType', 'double')    
for bin = 1:0.1:2
     rows = find(DAT(:,27) > bin);
     p(bin) = DAT(rows,:);
end
disp(p(1.2))

It could be more convinient.

Sign up to request clarification or add additional context in comments.

Comments

1

how about

bins = 1:0.1:2;
for ii = 1: numel(bins)
    bin = bins(ii);
    rows = find( DAT(:,27) > bin );
    p{ii} = DAT(rows,:);
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.