Why I get extra columns with irrelevant results?

1 vue (au cours des 30 derniers jours)
Stelios Fanourakis
Stelios Fanourakis le 24 Fév 2019
Hi
I use those lines to get the number of pixels among several rows and columns
for col = 390 : 466
h = imdistline(gca,[427 427],[215 370]);
dist(col) = getDistance(h)
end
Then I use this line to export them in excel
data = [dist(:)];
t = table(data);
writetable(t,'YourFile555.xls','Sheet',1,'Range','AD1:AD520')
Other times, when the Range exceeds the pixel values of the image I am supposed to get from dist, then the exceeding cells of the excel would get 0 value.
In my case, I get the correct values up until the 466 column as I have defined in the for loop and then it fills with irrelevant values, the rest of the columns until 520 as I have declared in the Range. Why is that?
155 is the correct value of the image I am using, the rest 83 that you see are values of a previous image. Not the one I am currently use. Why Matlab gets confused??
Columns 457 through 475
155 155 155 155 155 155 155 155 155 155 83 83 83 83 83 83 83 83 83
Columns 476 through 494
83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83
Columns 495 through 508
83 83 83 83 83 83 83 83 83 83 83 83 83 83
I don;t have any other line in the code that refers to the previous image. Just the ones I write here.
Any possible explanation please?

Réponse acceptée

Matt J
Matt J le 24 Fév 2019
My guess is that you are writing into the same file as the previous image, but with a shorter list of values. The preceding values are still there because you did not clear them and the list of new values is too short to overwrite them all.
  5 commentaires
Matt J
Matt J le 24 Fév 2019
Modifié(e) : Matt J le 25 Fév 2019
When the essential values are changed and Run the script, why it should remember previous values?
Because unlike mfunction files, scripts don't have their own workspace. Any variables generated when you run a script reside in the workspace where the script is run, and remain there until you clear them. So, when you run the script a second time, assignment commands like,
dist(col) = getDistance(h)
are just modifying the contents of the dist variable previously created. They aren't creating it from scratch.
Just put in a "clear" command as the first line of the script and it should fix that problem.
Stelios Fanourakis
Stelios Fanourakis le 25 Fév 2019
Yeah, thanks. Most probably this was the case.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by