![](/img/trans.png)
[英]Invalid operands to binary expression ('double' and 'double *')
[英]Invalid operands to binary expression ('NSMutableArray' and 'double')
我想將 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;
您正在使用NSMutableArray
類型的storeImpedance
並且此表達式中的預期類型是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
中的每個值計算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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.