Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
//z[kl]=kld_conv[round((kl-1)*1/pgfactor)+1];
I have already an kld_conv[] ,which consist of values of size 999
sample_length=80000
I want to put the value of kld_conv respected index to z_round.

double *z;
z=(double*)malloc(sample_length* sizeof(double));
double *z_round;
z_round=(double*)malloc(sample_length* sizeof(double));

for(kl=0;kl<sample_length;kl++)
{
z[kl]=(float)((kl-1)*(1/pgfactor));
int index=round(z[kl])+1;
z_round[kl]=kld_conv[index];
//printf("%f\t ",z_round[0][kl]);
} 
//printf("\n\n");

but the value of z_round is giving all 0 which it should not be.
Posted
Comments
chandanadhikari 8-Jan-15 2:07am    
can you please show what are the types of sample_length, kl, pgfactor and what are their values.
Jochen Arndt 8-Jan-15 3:01am    
Print out all intermediate results and compare them with the expected values. Than you can see which part of your calculation fails.

The first printf is commented but accesses a 2-dim array while z_round is only 1-dim. This will fail when uncommenting.
KarstenK 8-Jan-15 7:41am    
Why arent you use a struct or class. Write a small sample/test code to see your problem.

Cast to double => write cleaner code...

1 solution

sample_length is just int value ..
And I got the issue solved pgfactor value was wrongly assign now its working as per the requirement.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900