How to write a for loop code with an undetermined value

I am stuck while writing this code. Could you give any advise? The matrix N might consist of 16 different values at maximum(0-16), depending on the previous codes.
x=-20:5:20;
y=-20:5:20;
z=40:5:80;
[X,Y,Z]=meshgrid(x,y,z)
h=0;
for i=1:1:length(x)
for j=1:1:length(y)
for k=1:1:length(z)
h=h+1
M(h,:)=[X(i,j,k), Y(i,j,k), Z(i,j,k)];
% N(h)=a_MATLAB_function([M(h,1); M(h,2); M(h,3) ],[0;0;0]);
end
end
end
N=[12 12 12 12 12 12 12 8 4 4 4 12 12 ]; % Matrix N's size is 1x729 actually.
% Here it is simplified as a shorter row.
NN = unique(N); NN_length=length(NN);
S=[35 50 100 200];
figure; hold on;
for i=1:1:NN_length
NNN(i,:)=find(N==NN(i))
scatter3(M(NNN(i,:),1),M(NNN(i,:),2),M(NNN(i,:),3),S(i))
end
hold off;
For the first value of i=1, it is fine. But later I receive error. Because while writing the second row of NNN, first row and second row dimension doesn't match. What can I do? Thanks in advance.

 採用された回答

Jan
Jan 2021 年 2 月 7 日
編集済み: Jan 2021 年 2 月 7 日

1 投票

Is there a reason to collect NNN in an array?
for i = 1:NN_length
NNN = (N == NN(i)); % Without FIND: faster logical indexing
scatter3(M(NNN, 1), M(NNN, 2), M(NNN, 3), S(i))
end
If you do need NNN later on:
NNN = cell(1, NN_length)
for i = 1:NN_length
NNN{i} = (N == NN(i)); % Without FIND: faster logical indexing
scatter3(M(NNN{i}, 1), M(NNN{i}, 2), M(NNN{i}, 3), S(i))
end

8 件のコメント

ercan duzgun
ercan duzgun 2021 年 2 月 7 日
@Jan yes you are right. No need to collect NNN in array. Thank you very much for your help. I appericate your help.
acun67 acu
acun67 acu 2021 年 2 月 8 日
@Jan I could not find any way to direct massage you thats why i post my question in this thread.
sometime earlier i was using a "portable" matlab for learning purpose. I did not install it in my system and i needed any licence key. the whole set up i carried in a pen drive in a zip file. I unziped it and used it. however that model had some limitation. I need that type of IDE/ verson now (argent).
can you/ any one help me by providing that version name?
Walter Roberson
Walter Roberson 2021 年 2 月 8 日
Is it possible you are thinking of Octave ?
acun67 acu
acun67 acu 2021 年 2 月 8 日
@Walter Roberson thank you for your advice. Once/twise I used octave, I am not very much confident in octave.
presntly I want to read(import) ,write and plot some file . previouly I have done this in matlab thats why searching for this.
Walter Roberson
Walter Roberson 2021 年 2 月 8 日
The closest thing to what you describe that I can recall was some cracked versions of MATLAB.
It is true, though, that for some kinds of Standalone Named User (SNU) Licenses it is possible to use Mathworks as the license administrator; in such a case it would be possible to install from a pen drive, but there was no special version for this, and no special IDE.
There is MATLAB Online, matlab.mathworks.com, but it does not require installation.
acun67 acu
acun67 acu 2021 年 2 月 8 日
@Walter Robersonthank you. matlab online is the last option for me right now. But i did not install that version from pendrive. i just copied and pasted it. is there any way i can get that SNU name or crack name?
Walter Roberson
Walter Roberson 2021 年 2 月 8 日
The steps to enable a license to use Mathworks itself as the license server are described at https://www.mathworks.com/help/licensingoncloud/matlab-on-the-cloud.html .
This is available for individual licenses -- Educational or Standard (commercial / professional), but not for Home or Student licenses.
If I recall correctly, the people who offered that old cracked software were arrested for software piracy.
acun67 acu
acun67 acu 2021 年 2 月 9 日
thank you for sharing your knowledge.I am not using this installation and will try to solve my problem using Matlab online.

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

その他の回答 (1 件)

David Hill
David Hill 2021 年 2 月 7 日

0 投票

What are you trying to plot? What is M?
[n,nn,nnn]=unique(N);%;might want to look at the outputs here, they might help you

1 件のコメント

ercan duzgun
ercan duzgun 2021 年 2 月 7 日
@David Hill , Sorry I forgot about M. Now I edited the codes. M is meshgrid and locations of points in 3D.

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

カテゴリ

ヘルプ センター および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

リリース

R2020b

タグ

質問済み:

2021 年 2 月 7 日

コメント済み:

2021 年 2 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by