我想将double值存储到Array中,然后合并以计算一些结果,但是遇到了一些错误。还有另一种方法吗?
NSMutableArray *storeImpedance;
NSMutableArray *storeLength;
double designFrequency = 1e9;
double simulateFrequency = 1.5e9;
double pi = 3.14159265359;
double omega = 2*pi*simulateFrequency;
double Z0=50;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
storeImpedance = [[NSMutableArray alloc]initWithCapacity:25];
storeLength = [[NSMutableArray alloc]initWithCapacity:25];
}
- (IBAction)addButton:(UIButton *)sender {
storeCount++;
[storeImpedance addObject:[NSNumber numberWithDouble:[impedanceTextField.text doubleValue]]];
[storeLength addObject:[NSNumber numberWithDouble:[lengthTextField.text doubleValue]]];
}
if (imageIndex==1)
{
thetarad=storeImpedance*pi/180*simulateFrequency/designFrequency;
A=cos(thetarad);
B=I* storeImpedance*sin(thetarad);
C=I*sin(thetarad)/storeImpedance;
D=cos(thetarad);
}
在这一行:
hetarad=storeImpedance*pi/180*simulateFrequency/designFrequency;
您正在使用storeImpedance
这类型的NSMutableArray
,在这种表达式的预期类型double
。
double
从数组中提取所需的值,并使用它来解决问题:
NSNumber *number = (NSNumber *)[storeImpedance firstObject]; // Or use objectAtIndex: for a specific value in the array if it is not the first one
double value = [number doubleValue];
hetarad=value*pi/180*simulateFrequency/designFrequency;
如果要计算hetarad
数组中的每个值:
for (id element in storeImpedance) {
NSNumber *number = (NSNumber *)element
double value = [number doubleValue];
hetarad=value*pi/180*simulateFrequency/designFrequency;
// You should do something with hetarad here (either store it or use in other required logic otherwise it will be overwritten by the next iteration
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句