Error in `ggsave()`: ! Dimensions exceed 50 inches (`height` and `width` are specified in inches not pixels). ℹ If you're sure you want a plot that big, use `limitsize = FALSE`. Run `rlang::last_trace()` to see where the error occurred.怎么修改
时间: 2023-07-28 11:07:04 浏览: 894
这个错误提示是因为你保存的图片的高度和宽度超过了50英寸,而ggsave函数默认的单位是英寸而不是像素。
如果你确定要保存这么大的图片,可以在ggsave函数中添加参数"limitsize = FALSE"来禁用尺寸限制。例如:
```
ggsave("plot.png", plot = myplot, width = 60, height = 40, limitsize = FALSE)
```
这将允许你保存60英寸宽,40英寸高的图片,但请注意这可能会导致一些显示问题,因为这样的图片可能太大了。
如果你不需要这么大的图片,可以调整width和height的值,使其小于50英寸。或者,你可以将height和width的单位修改为像素,例如:
```
ggsave("plot.png", plot = myplot, width = 3000, height = 2000, units = "px")
```
这将保存一个3000像素宽,2000像素高的图片,而不会有尺寸限制的错误。
相关问题
Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.String
这个错误是因为在使用String.format方法时,格式化字符串中的占位符类型与实际参数类型不匹配导致的。具体来说,在格式化字符串中使用了%f格式化符号表示输出浮点数,但是实际参数类型是String类型,所以会抛出IllegalFormatConversionException异常。
要解决这个问题,需要将实际参数类型改为浮点数类型,或者将格式化字符串中的占位符类型改为字符串类型。以下是两个修改方案:
1. 将实际参数类型改为浮点数类型
```java
double x = 0.75;
String message = String.format("Exceed %.0f%%. Ticket 200", x * 100);
System.out.println(message);
```
在这个代码中,我们将实际参数x乘以100,得到一个浮点数类型的百分数,然后使用%.0f%%格式化字符串输出。最终结果为"Exceed 75%. Ticket 200"。
2. 将格式化字符串中的占位符类型改为字符串类型
```java
String x = "75";
String message = String.format("Exceed %s%%. Ticket 200", x);
System.out.println(message);
```
在这个代码中,我们将实际参数x改为字符串类型,然后使用%s%%格式化字符串输出。最终结果同样为"Exceed 75%. Ticket 200"。
代码报错Index in position 2 exceeds array bounds. Index must not exceed 3.
根据您提供的代码,错误“Index in position 2 exceeds array bounds. Index must not exceed 3”通常表示在尝试访问数组的某个维度时超出了该维度的有效索引范围。在这个特定情况下,可能的原因是尝试访问一个只有3列的矩阵的第4列或更高列。
检查以下部分代码,可能会找到问题所在:
1. **初始状态向量 `h0` 和最终状态向量 `hf`**:
```matlab
h0 = [100, -200, 400; 0, 0, -10];
hf = [0, 0, 0; 0, 0, 0];
```
这两个矩阵都是 2x3 的,即有两行三列。
2. **状态变量的下限和上限 `hmin` 和 `hmax`**:
```matlab
hmin = [-200, -200, 0; -10, -10, -10];
hmax = [400, 400, 400; 10, 10, 10];
```
这两个矩阵也是 2x3 的。
3. **连续函数 `mlocpContinuous` 中的状态和控制变量**:
```matlab
function phaseout = mlocpContinuous(input)
g = input.auxdata.g;
t = input.phase.time;
x = input.phase.state(:,1:3);
v = input.phase.state(:,4:6);
u = input.phase.control;
dx = v;
dv = u - [0, 0, g];
phaseout.dynamics = [dx; dv];
phaseout.integrand = sum(u.^2, 2);
end
```
在这里,`input.phase.state` 被假设为一个 2x6 的矩阵(前3列为位置,后3列为速度)。如果 `input.phase.state` 实际上只有 2x3 或更少的列,那么 `v = input.phase.state(:,4:6)` 将会引发错误。
### 解决方法
1. **检查 `input.phase.state` 的实际大小**:
在 `mlocpContinuous` 函数中添加一些调试输出,查看 `input.phase.state` 的大小:
```matlab
function phaseout = mlocpContinuous(input)
g = input.auxdata.g;
t = input.phase.time;
disp(['Size of input.phase.state: ', num2str(size(input.phase.state))]);
x = input.phase.state(:,1:3);
v = input.phase.state(:,4:6);
u = input.phase.control;
dx = v;
dv = u - [0, 0, g];
phaseout.dynamics = [dx; dv];
phaseout.integrand = sum(u.^2, 2);
end
```
2. **调整状态向量的定义**:
如果发现 `input.phase.state` 只有 2x3 的大小,需要调整状态向量的定义,使其包含所有必要的状态变量(位置和速度)。
3. **检查初始化猜测量 `h_guess`**:
确保 `h_guess` 包含了所有必要的时间点和状态变量:
```matlab
h_guess = [h0; hf];
```
通过这些步骤,您可以更好地定位并解决导致索引超出范围的问题。
阅读全文
相关推荐
















