필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
BUGATHA VARALAKSHMI
BUGATHA VARALAKSHMI 2017년 1월 20일
편집: Stephen23 2017년 1월 20일
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