Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
For the code below how would I make it ALWAYS select and set the upper left corner to be 1 always no matter what the n value is (10, 1000, 1000000)?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
n=10; % number of nodes in the x-direction
meshsize = n*n/2;
nodes = 1:meshsize;
nodetype = zeros(n/2, n);
delx = 2/n;
[X,Y] = meshgrid(delx:delx:2,delx:delx:1);
for i = 1:length(nodes)
if X(i) == .2 && Y(i) == .2 %DOESNT SCALE
nodetype(i) = 1;
%FOR TOP LEFT CORNER
end
2 Kommentare
KALYAN ACHARJYA
am 2 Okt. 2018
Still, Question is not clear for me, can you elaborate more?
Be Specific?
Antworten (1)
Dennis
am 2 Okt. 2018
I am only guessing, but i assume you want nodetype(1,1) to be 1? The easiest way of doing this would be:
nodetype(1,1)=1;
actually this does the same:
nodetype(1)=1;
Now your loop does not set the top left corner to 1, but rather checks for 0.2 values. However depending on your n it is very possible that there are none in your matrix. This is obvious for n=98, but it is also true for n=100, although the variable inspector might tell you something different on the first look.
The reason for this is that not every floating point number can be represented exact in binary form. For more information on this topic please look here.
1 Kommentar
Stephen23
am 2 Okt. 2018
Bearbeitet: Stephen23
am 2 Okt. 2018
"... not every floating point number can be represented exact in binary form"
By definition, all binary floating point numbers are stored in a binary form, which exactly represents that floating point number... did you actually mean something like "not all decimal fractions are representable using (finite) binary floating point numbers"?
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!