我正在尝试使此代码正常工作,但我无法解决问题...
img = imread('cameraman.tif');
for i = 1:8
a{i}=bitget(img,i);
subplot(2,4,i), imshow(logical(a{i})), title('Bit plane');
end
输出错误是
Unable to perform assignment because brace indexing is not supported for variables of this type.
Error in (line 15)
a{i}=bitget(img,i);
您看到问题出在哪里吗?谢谢
答案 0 :(得分:0)
该错误消息表明a
不支持大括号索引。这意味着在运行代码之前,a
已经被定义。
要编写可靠的代码,应始终初始化所有变量。在这种情况下,请在循环前写入a = {};
。这样可以确保a
的类型正确。
更好的方法是预先分配a
使其具有正确的大小,这样就不会在每次循环迭代时都调整其大小:
a = cell(8,1);
答案 1 :(得分:0)
我使用 MATLAB 进行了 8位平面的工作,这是我的代码供您参考:)
class SellPageViewModel : ViewModelBase
{
public SellPageViewModel()
{
Vehicle = new Vehicle();
SaveVehicleCommand = new Command(SaveVehicle);
SetNewCommand = new Command(SetNew);
SetUsedCommand = new Command(SetUsed);
}
private Vehicle vehicle;
public Vehicle Vehicle
{
get { return vehicle; }
set
{
SetProperty(ref vehicle, value);
Console.WriteLine("Vehicle details entered");
}
}
private object categorySelection;
public object CategorySelection
{
get { return categorySelection; }
set
{
SetProperty(ref categorySelection, value);
Category catToInt = (Category)value;
if (value != null)
Vehicle.CategoryId = catToInt.Id;
}
}
private int selectIndex;
public int SelectIndex
{
get { return selectIndex; }
set
{
if (value != -1)
SetProperty(ref selectIndex, value);
}
}
public Command SetNewCommand { get; }
public Command SetUsedCommand { get; }
public Command SaveVehicleCommand { get; }
void SetNew()
{
Vehicle.Condition = "New";
}
void SetUsed()
{
Vehicle.Condition = "Used";
}
async void SaveVehicle()
{
Console.WriteLine("Save Button Clicked");
Console.WriteLine(Vehicle.Title);
Console.WriteLine(Vehicle.Price);
Console.WriteLine(Vehicle.CategoryId);
Console.WriteLine(Vehicle.Condition);
SelectIndex = 0;
Vehicle = new Vehicle();
}
}