英文:
MATLAB sparse must be same length
问题
我正在尝试运行一个旧的Matlab脚本。它来自于此处最小曲率格网算法的旧实现:https://github.com/duncombe/matlab/blob/master/saga/。我的问题出现在脚本uniquept.m的第a = sparse(ind,1,f(:,jj));行:https://github.com/duncombe/matlab/blob/master/saga/uniquept.m。
% 寻找唯一点(R中的行)
[Ro,ind,c] = unique(R);
len = length(c);
% 如果没有重叠点,快速退出
if len==np,
Ro = R; fo = f; return
end
% 将值f映射到fo..............
fo = zeros(len,dim_f);
for jj = 1:dim_f
a = sparse(ind,1,f(:,jj));
fo(:,jj) = full(a)./c;
end
输入是X、Y和Z的值。对于这个函数,R = [X Y],f = Z。
ind = 唯一的X,Y位置
f(:,jj) = f(:, 1) 所有Z值
我正在运行Matlab 2022a,这导致X,Y位置的数量少于Z值的数量。我假设原始作者的情况是可以的,那么以前的Matlab版本的sparse函数是否接受不同长度的向量?
英文:
I am trying to get an old Matlab script going. It comes from an old implementation of the minimum curvature gridding algorithm from here:
https://github.com/duncombe/matlab/blob/master/saga/
My problem occurs in the script uniquept.m on the line a = sparse(ind,1,f(:,jj));
https://github.com/duncombe/matlab/blob/master/saga/uniquept.m
% Find unique points (rows in R)
[Ro,ind,c] = unique(R);
len = length(c);
% Quick exit if no coincident points
if len==np,
Ro = R; fo = f; return
end
% Map values f to fo ...............
fo = zeros(len,dim_f);
for jj = 1:dim_f
a = sparse(ind,1,f(:,jj));
fo(:,jj) = full(a)./c;
end
The input are X, Y and Z values. For this function,
R = [X Y]
f = Z
ind = unique X,Y positions
f(:,jj) = f(:, 1) so all of the Z values
I am running Matlab 2022a, and this makes the number of X,Y positions less than the number of Z values. I assume it worked for the original author so did previous versions of Matlab's sparse function accept vectors of different lengths?
答案1
得分: 1
看起来我需要在唯一函数调用中添加"rows",并在稀疏调用中过滤相应的Z值。
编辑:这意味着自1995年以来,唯一函数可能已经发生了变化。
英文:
Looks like I need to add "rows" to the unique function call, and filter for corresponding Z values in the sparse call.
Edit: which means the unique function has probably changed since 1995 when this was written.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论