Error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts

Hi,
I have been working in a code to detect the point where a line intersects a curve. In order to do that I have been using the function polyxpoly.
clear all
clc
file = csvread('PSD_ETSI.csv',1); %Reading PSD file
skew = file(:,1); %Taking skew value from file
psd = file(:,2); %Taking psd value from file
margin = 4; %Selecting margin
for i=1:length(skew)
sk_0max(:,:,i) = plus(skew(i).*ones(length(skew),1),margin.*ones(length(skew),1)); %Evaluating margin
psd_0(:,1,i) = psd.*ones(length(skew),1);
skew_0(:,1,i) = skew.*ones(length(skew),1);
[x_0max(:,:,i),y_0max(:,:,i)] = polyxpoly(sk_0max(:,:,i),psd_0(:,1,i),skew,psd,'unique');
hold on
plot(skew,psd)
plot(sk_0max(:,:,i),psd)
end
The thing with the code is that it works fine for some margin values but for some others it just breaks the code and show the non-singleton rhs error . I have debugged the code and I have seen that at some values of i the values at x_0max,y_0max appears to be empty, the thing is that I cannot understand why.
I attached the .csv file in case you want to run the code and try it. The margins that I have been testing are between 0 and 9.
I would appreciate any hint or help regarding to this.
Best regards.

 採用された回答

Star Strider
Star Strider 2016 年 11 月 12 日
I don’t have the Mapping Toolbox, so I can’t run your code. Probably the best approach is not to assign the polyxpoly outputs directly to your array. Output them to temporary variables, trap the empty outputs, and only assign the values to your array if they are not empty.
Example:
[Temp1, Temp2] = polyxpoly(sk_0max(:,:,i),psd_0(:,1,i),skew,psd,'unique');
if (~isempty(Temp1)) && (~isempty(Temp2))
x_0max(:,:,i) = Temp1;
y_0max(:,:,i) = Temp2;
end
This may solve the problem with the thrown error. You need to troubleshoot the reason the error was thrown.
NOTE This is obviously UNTESTED CODE.

2 件のコメント

Gustavo Gonzalez
Gustavo Gonzalez 2016 年 11 月 14 日
Hi Star Strider,
Thank you very much for your answer. It allowed me to see what was happening with the program when the values were assigned to the temporal variable. However, I am still having the problem but I realized that it is an issue with the data in the file. At some regions of the curve it is fine but when lines intersect the curve in a region where values are almost the same the error appears again.
I will try to rearrange the data inside the file in order to skip that error.
Thanks again for your help.
Regards.
Star Strider
Star Strider 2016 年 11 月 14 日
My pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by