Error using accumarray First input SUBS must contain positive integer subscripts.

I am very much troubled solving this:
>> [X, Y, Z]=ndgrid(x,y,z);
>> C = round(ceil(Y./Z));
>> N = accumarray([X(:), C(:)], M(:));
Error using accumarray
First input SUBS must contain positive integer subscripts.
data file attached
I have already read all questions and answers about it here, cant figure out whats wrong.
thanks

Risposte (2)

"I have already read all questions and answers about it here, cant figure out whats wrong."
After reading many answers, you should know by now that indices must be positive integers.
Now take a look at your x data:
>> x(:)
ans =
0.00000
0.05000
0.10000
0.15000
0.20000
0.25000
0.30000
0.35000
0.40000
0.45000
0.50000
0.55000
0.60000
0.65000
0.70000
0.75000
0.80000
0.85000
0.90000
0.95000
1.00000
How many of those values are positive integers? How many of those values can be used as indices?
Yet you try to use X (which simply contains values from x) as indices.

4 Commenti

this should have solved the problem then?
>> [X, Y, Z]=ndgrid(x*100,y*100,z*100);
>> C = (ceil(Y./Z))*100;
N = accumarray([X(:), C(:)], M(:));
Error using accumarray
First input SUBS must contain positive integer subscripts.
as I said, I have no clue.
thanks
"this should have solved the problem then?"
You have not described what you are trying to achieve, or what the expected result should be, so I have not idea what you need to do to "solve" the problem.
Taking a wild guess in the dark: perhaps you need reshape, rather than accumarray (if you don't know what indices are and how to use accumarray it is a rather unusual choice of function).
@Asliddin Komilov : that is a different question. I will take a look at your other question.
As far as I can tell, I have answered the question that you asked at the top of this page (which was "what is wrong with my code?").

Accedi per commentare.

You also posted this in
and I gave a complete code solution there.
Your question there that led me to create that code for you had been strictly positive integers, but it turned out that your real data involved negatives for Z, and involved 0 as well as positive integers for Y, and involved real-valued X from 0 to 1. Those are quite different conditions that should have been stated ahead of time.

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Prodotti

Richiesto:

il 14 Set 2019

Risposto:

il 15 Set 2019

Community Treasure Hunt

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

Start Hunting!

Translated by