iam getting an error in:f=strcat(filename,3)

1 次查看(过去 30 天)
File_Name = imread('E:\PPTFILES\perl pgms\yrMXs.tif');
Band_Number = 3;
f = strcat( File_Name,3);
[G,~] = geotiffread(f);
clearvars 3 f
Band_Number = 4;
f = strcat( File_Name, 4);
[R, ~] = geotiffread(f);
clearvars 4 f
Band_Number = 5;
f = strcat( File_Name, 5);
[NIR, ~] = geotiffread(f);
clearvars File_Name 5 f
G_heq = histeq(G);
R_heq = histeq(R);
NIR_heq = histeq(NIR);
NIR = double(NIR_heq);
R = double(R_heq);
G = double(G_heq);
NDVI = (NIR -R) / (NIR + R);
figure(), imshow(NDVI, []), title('NDVI');
colormap(jet);
colorbar;
impixelinfo
  2 个评论
Walter Roberson
Walter Roberson 2017-1-20
What is the result you are looking for out of your statement
f = strcat( File_Name,3);
For example are you hoping for
E:\PPTFILES\perl pgms\yrMXs.tif3
or for
E:\PPTFILES\perl pgms\yrMXs3.tif
?
Stephen23
Stephen23 2017-1-20
编辑:Stephen23 2017-1-20
And what is the intention of taking the output of imread and passing it as an input to strcat?
File_Name = imread('E:\PPTFILES\perl pgms\yrMXs.tif');
Band_Number = 3;
f = strcat( File_Name,3);
As its documentation clearly states, imread returns an image as an array. strcat concatenates strings together.
This code has many bugs. It has many bugs because the way you are writing your code lets you write lots of bugs. Beginners often seem to write lots of code without checking it as they write it. Then they are surprised when the code does not run, and have no idea where the errors are in the large block of code. They are unable to cope, and they actually have no idea what their code is doing. How do you end up with twenty lines of code when the first few lines are buggy? Were they tested?
Writing lots of code does not mean that you have solved your task. Having lots of code does not mean that you have done good work. It is a waste of your time. You need to first understand how to implement your algorithm, write it, and test it as you write it. Write one line or operation, then test it. Check that it does exactly what you need it to do. Do not move on until it is correct. Then you will not end up with a huge collection of bugs like this code.
You also need to learn to pay attention to what the MATLAB editor is telling you. The editor shows you where bugs are, and where you can make your code better.
When you learn how to check and debug your own code than you do not need to rely on coming to internet forums to make your code work. You could do it yourself.
You also need to learn to read the documentation. The documentation tells us all how to use MATLAB. It tells us how to call functions. It tells us what inputs and outputs functions have. Reading the documentation would help to understand that passing imread's output to strcat is meaningless. And that 3, 4, and 5 are not valid MATLAB variable names so this is an error:
clearvars 3 f
To start to learn how to use MATLAB you should do the introductory tutorials:
And also read this:
PS: JET is a bad choice of colormap. Use PARULA instead.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by